我对 ajax 和 jquery 非常陌生,所以请耐心等待。我目前正在构建一个小型应用程序,它将执行告诉您网站状态代码的基本任务,并根据返回的代码执行某些操作。我在网上找到了这段代码,如果http状态码是404,它会返回“找不到页面”。
$(function() {
var url = "http://www.google.com";
$.ajax(url,
{
statusCode: {
404: function() {
alert('page not found');
}
}
});
});
但是,如何将原始状态代码值保存到变量中,而不是检查 404 状态代码?
谢谢!
最佳答案
希望这样的事情可以帮助你交配..:)
error:function (xhr, ajaxOptions, thrownError){
alert(xhr.status);
switch (xhr.status) {
case 404:
// Desired Action.
}
}
complete: function(xhr, statusText){
alert(xhr.status);
}
您可以在下面的链接中获得相当多的信息
关于jquery - 从此 ajax 调用获取 http 状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19897866/