开发者

how to return 404 status in jquery

I call the load method. There are some occa开发者_开发技巧sions when the page it calls does not exist. In firebug I can see the 404 status is returned. How can I access this status in jQuery so I can handle it?

$("#section-main-wrapper").load(uri);


Pass in a callback function:

$("#section-main-wrapper").load(uri, null, function(response, status, xhr) {
    // Check status
});


http://docs.jquery.com/Ajax/load

$(...).load(url, null, function (responseText, textStatus, XMLHttpRequest) cb {
  this; // dom element
});


$.ajax({
  url: uri,
  cache: false,
  success: function(html){
    $("#section-main-wrapper").replaceWith(html);
  },

  error: function (XMLHttpRequest, textStatus, errorThrown) {
    // Do something here
    this; 
  }  
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜