gpt4 book ai didi

javascript - 如何获取 jquery ajax 状态码

转载 作者:可可西里 更新时间:2023-11-01 02:35:23 25 4
gpt4 key购买 nike

我想知道我们如何在 jquery 中获取 ajax 状态码。我有这个 ajax block :

$.ajax{
type: "GET",
url: "keyword_mapping.html",
data:"ajax=yes&sf="+status_flag,

success: callback.success,
complete: rollup_filters(),
failure: function(){
alert("Failure");
}
}

现在在上面的代码中,如果失败,我如何获得ajax状态代码和该状态代码的一些描述??

最佳答案

您想使用 error捕捉这个的选项。例如:

error: function (jqXHR, textStatus, errorThrown)
// Your handler here...
}

然后您可以使用 jqXHR 对象来检索有关失败的信息。

From the documentation :

For backward compatibility with XMLHttpRequest, a jqXHR object will expose the following properties and methods:

  • readyState
  • status
  • statusText
  • responseXML and/or responseText when the underlying request responded with xml and/or text, respectively
  • setRequestHeader(name, value) which departs from the standard by replacing the old value with the new one rather than concatenating the new value to the old one
  • getAllResponseHeaders()
  • getResponseHeader()
  • abort()

关于javascript - 如何获取 jquery ajax 状态码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7078978/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com