开发者

Problem with $.getJSON on IE

开发者 https://www.devze.com 2023-03-30 12:01 出处:网络
i have an application calling a jquery function, like this: $.getJSON(\'test.php\',{dest:2},function(data){

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

0

精彩评论

暂无评论...
验证码 换一张
取 消