jquery - PHP JSON response contains HTML headers -
i've got strange problem i'm trying write php page returns json jquery ajax call. problems despite setting content type application/json, response seems include html header.
here's php code:
// code generates 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) { // show message saying it's been sent! alert('success!'); }, error: function(xmlhttprequest, textstatus, errorthrown) { alert('error!'); } }); the response seems 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 returns","10.000000","aud"],["2007-08-06","91111895","credit returns","320.000000","aud"],["2007-09-03","91128486","credit memo","5.000000","aud"],["2007-09-03","91128487","credit etc, etc and according response header thinks it's json:
http/1.1 200 ok content-type: application/json server: microsoft-iis/7.5 x-powered-by: php/5.3.3 whenever run code , alert "error!" gets fired every time, understandable... got ideas why html being included in response?
calling header() has nothing html-code being returned in response.
header() used set http-headers, while html-code (<!doctype html public "-//w3c//dtd html 3.2//en">) sent in body of http response.
so line of code
header("content-type: application/json"); does job correctly because response contains correct content type:
content-type: application/json so what's wrong? have code executed before code deals json. should send json encoded message in response without html tags , terminate script using exit or die. try locate code sends html tags , put code before it.
Comments
Post a Comment