I have a strange problem when I try to write a PHP page that returns some JSON on a jQuery AJAX call. The problems are that although the / json application is used for the content type, the answer always seems to include the HTML header.
Here's the PHP code:
// some code that generates an array header("Content-type: application/json"); echo json_encode($return);
Then in Javascript:
$.ajax({ url: '/VAPHP/services/datatable.php', dataType: 'json', data: { type: 'invoices' }, success: function(data) {
The answer always looks something like this:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN"> <html> <head> <title></title> </head> <body> {"aaData":[["2007-08-01","91109507","Invoice","10.000000","AUD"],["2007-08-02","91110103","Invoice","5.000000","AUD"],["2007-08-02","91110122","Invoice","305.000000","AUD"],["2007-08-02","91110129","Invoice","320.000000","AUD"],["2007-08-03","91111146","Credit for Returns","10.000000","AUD"],["2007-08-06","91111895","Credit for Returns","320.000000","AUD"],["2007-09-03","91128486","Credit Memo","5.000000","AUD"],["2007-09-03","91128487","Credit etc, etc
And according to the response header, he certainly considers this JSON:
HTTP/1.1 200 OK Content-Type: application/json Server: Microsoft-IIS/7.5 X-Powered-By: PHP/5.3.3
Whenever I run the code, it warns "Error!". gets fired every time, which is understandable ... Does anyone have any idea why HTML is included in the response?