how to return 404 status in jquery

2019-07-24 12:31发布

I call the load method. There are some occasions 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);

标签: jquery
3条回答
来,给爷笑一个
2楼-- · 2019-07-24 13:02

Pass in a callback function:

$("#section-main-wrapper").load(uri, null, function(response, status, xhr) {
    // Check status
});
查看更多
看我几分像从前
3楼-- · 2019-07-24 13:10

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

$(...).load(url, null, function (responseText, textStatus, XMLHttpRequest) cb {
  this; // dom element
});
查看更多
相关推荐>>
4楼-- · 2019-07-24 13:18
$.ajax({
  url: uri,
  cache: false,
  success: function(html){
    $("#section-main-wrapper").replaceWith(html);
  },

  error: function (XMLHttpRequest, textStatus, errorThrown) {
    // Do something here
    this; 
  }  
});
查看更多
登录 后发表回答