Problem with $.getJSON on IE
i have an application calling a jquery function, like this:
$.getJSON('test.php',{dest:2},function(data){
alert(data);
});
Well, the test.php is like this:
<?php echo json_encode('Test'); ?>
On FF returns an alert with 'Test', but on IE return an alert without anything开发者_运维知识库.
anyone have any idea?
Add mime-type to your php headers. IE does not get it automatically.
You are missing content-type application/json as your header.
Add this, before the echo:
header('Content-type: application/json');
A JSON document must consist of an array or an object.
If you give json_encode
a string, then PHP will output a string, which is not a valid JSON document.
You are probably running into differences between the ability of the different JSON parsers used in different browsers to error recover.
solved, follow what I did:
replaces the call
$.getJSON('test.php',{dest:2},function(data){
alert(data);
});
for this
$.ajax({
type: "get",
url: "test.php",
data: "dest=2",
cache:false,
dataType:'json',
success: function(data){
alert(data)
}
});
like this works on IE and FF
精彩评论