I recently started translating an old Classic ASP
site to PHP
. Several of its pages (Response.ContentType = "application/json")
would just serve JSON
responses such as {"R":1}
and everything worked fine.
now on PHP, with header("content-type:application/json")
first thing on the code, ajax just will not parse it. The client-side JS code is the same I used before. I haven't even touched it.
$.ajax({
dataType: "json",
type : "POST",
url: "processthisrequest.php",
cache: false,
async: false,
data: { Field1:"bla", Field2:"blabla"},
error: function(data){
// code on error
},
success: function(json){
// code on success
}
});
if the request is accepted ALL it serves is {"R":1}
with double-quotes as it's always been.
Ajax will fire the error function no matter what. trying to debug it I found this:
readyState:4
responseText:{"R":1}
status:200
statusText:OK
searching for help I found a lot of people with problems with ajax getting readyState:4, status:200 and the response still not being parsed. none of the solutions worked or applied to my problem.
as it was working with IIS/ASP, can it be something with Apache or PHP?
UPDATE:
still no success, but if I get the server to serve a .js file with {"R":1}
instead of processing a response through a php page ajax will fire the success function. which only proves my point that this is a php problem and also explains why it worked with old dinosaur ASP. now why PHP is not serving a proper mime-type is something I am trying to figure out.