我对ajax和jquery很新,所以请耐心等待。我目前正在构建一个小应用程序,它将执行基本任务,告诉您网站的状态代码,并根据返回的代码执行某些操作。我在网上找到了这个代码,如果http状态代码是404,它会返回“找不到页面”。
$(function() {
var url = "http://www.google.com";
$.ajax(url,
{
statusCode: {
404: function() {
alert('page not found');
}
}
});
});
但是,如何将原始状态代码值保存到变量?而不是检查404状态代码? 谢谢!
答案 0 :(得分:3)
希望这样的事可能有助于你交配.. :)
error:function (xhr, ajaxOptions, thrownError){
alert(xhr.status);
switch (xhr.status) {
case 404:
// Desired Action.
}
}
complete: function(xhr, statusText){
alert(xhr.status);
}
U可能会在以下链接队友中获得大量信息