I have the following code:
$.ajax({type: 'get',
mode: 'abort',
dataType: 'json',
url: 'http://localhost/1.php',
data: {},
success: function(res){
alert(res);
},
timeout: 10000,
error: function(XMLHttpRequest, textStatus, errorThrown){
alert("ERROR L: " + textStatus + " (" + errorThrown + ")");
}
});
PHP contains only {id:1} and that’s it.
When I try to parse the code as is, I get:
ERROR L: parsererror (SyntaxError: Unexpected token i)
from the error handler I have.
If I change to dataType:'html',
Everything works just fine. I am missing something here, probably very very small, what is it?
The property names in JSON must be quoted:
The JSON specification specifies each name to be of type
stringand defines type string as: