I made an AJAX call and it works on FF & Chrome but not on IE 7-8-9. I'm loading a JSON file from my domain:
$.ajax({
url: 'js/jquery.desobbcode.json',
dataType: 'json',
cache: false,
success: function(json) {
alert('ok');
},
error: function(xhr, errorString, exception) {
alert("xhr.status="+xhr.status+" error="+errorString+" exception="+exception);
}
});
I also tried by adding contentType: 'application/json'
but I receive the same output which is :
xhr.status=200
error=parsererror
exception=SyntaxError Unterminated string constant
I checked my JSON file with JSONLint and it's OK. I checked if there is an extra comma and the content is also trimmed. See my JSON file
If I put dataType: 'text'
, I receive the OK alert but a debug popup too.
Could you help me? Regards.
IE is known to have issues with implied content types.
... the new XmlHttpRequest class in Internet Explorer 7 doesn’t implement setRequestHeader very intuitively. Instead of setting the specified header, it appends the value.
Try specifying a contentType
and check what's coming back from the server:
$.ajax({
url: 'js/jquery.desobbcode.json',
dataType: 'json',
contentType: "application/json; charset=utf-8",
...
});
You may also want to try sending blank data:
$.ajax({
url: 'js/jquery.desobbcode.json',
dataType: 'json',
contentType: "application/json; charset=utf-8",
data: {}
...
});
If you are using php script to echo your json as a string just put
header('Content-Type: application/json; charset=utf-8');
before
echo $jsonString
line.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With