开发者

$.getJSON - ajax is sent but callback function is ignored - Internet Explorer

So here is my function

function ajax(addr,loading, loadTo, json){
        addr = addr.replace(' ', '');
        if (loading){
                $("#"+loading).fadeIn();
        }

        if (json){
                $.getJSON(addr, function(data){
                        alert('whoooo working'); // <--- it never goes here
                        if (loading){
                                $("#"+loading).fadeOut();
                        }
                        procJSON(data);
                });
                return true;
        }
}

and I'm calling it 开发者_如何学JAVAwith

var postid = $(this).attr('data-postid');
ajax(url+'tools/delete/'+postid, 'loading'+postid, false, true);

ajax is sent, image (loading image) is showed, but callback function is never called.

Isn't that just new reserved value from that IE's big list? Yes I know, IE is not a valid browser, but I can't blame my customers


As it fails in specific browsers, it's likely that it is a combination of unexpected headers in the response, and how the browser handles the data based on that.

If for example the response has the content type text/html instead of application/json, the browser might try to turn the response content into a HTML document (by adding pre tags around it), which would then cause the JSON parsing to fail.

If you use the $.ajax method, you can also catch any error message, which would give you a clue to what's going on:

$.ajax({
  url: addr,
  dataType: 'json',
  success: function(data){
    alert('whoooo working'); // <--- it never goes here
    if (loading){
      $("#"+loading).fadeOut();
    }
    procJSON(data);
  },
  error: function(o,c,m) { alert(m); }
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜