ajax is sent but callback function is ignored

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 with

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); }
});
链接地址: http://www.djcxy.com/p/46100.html

上一篇: jquery + IE 7&8

下一篇: ajax被发送,但回调函数被忽略