简体   繁体   English

jQuery AJAX请求中的xhr,status和ex变量

[英]`xhr`, `status` and `ex` variables in a jQuery AJAX request

I am using jQuery 1.6 and I would like to know and understand how I can access response xhr , status and ex variables in the following code: 我正在使用jQuery 1.6,并且想知道和理解如何在以下代码中访问response xhrstatusex变量:

$jQuery.ajax({
  type:    "POST",
  url:     "<some_url>",
  error: function(xhr, status, ex) {
    var msg = "";
    if (xhr) {
      msg = "readyState is " + xhr.readyState + ". ";
    }
    if (ex) {
      msg += ex.name + ' - ' + ex.message;
    }
    alert("ERROR " + msg); }
  success: function(jqXHR, status, ex) {
    ...
  }
});

How can I know the full list of all them "accessible" values like, for example, readyState for the xhr ( xhr.readyState ), name and message for the ex ( ex.name and ex.message )? 如何得知所有“可访问”值的完整列表,例如xhr readyStatexhr.readyState ), ex namemessageex.nameex.message )?

Moreover, what xhr and ex variables represent (I think status refers to the HTTP status code)? 此外, xhrex变量代表什么(我认为status是指HTTP状态代码)?

I strongly suggest you to have a look at the docs . 我强烈建议您看一下文档

Here an example. 这里举个例子。

error(jqXHR, textStatus, errorThrown)Function 错误(jqXHR,textStatus,errorThrown)功能
A function to be called if the request fails. 如果请求失败,将调用的函数。 The function receives three arguments: The jqXHR (in jQuery 1.4.x, XMLHttpRequest) object, a string describing the type of error that occurred and an optional exception object, if one occurred. 该函数接收三个参数:jqXHR对象(在jQuery 1.4.x中为XMLHttpRequest),一个描述发生错误的类型的字符串,以及一个可选的异常对象(如果发生)。 Possible values for the second argument (besides null) are "timeout", "error", "abort", and "parsererror". 第二个参数(除null外)的可能值为“超时”,“错误”,“中止”和“ parsererror”。 When an HTTP error occurs, errorThrown receives the textual portion of the HTTP status, such as "Not Found" or "Internal Server Error." 发生HTTP错误时,errorThrown会接收HTTP状态的文本部分,例如“未找到”或“内部服务器错误”。 As of jQuery 1.5, the error setting can accept an array of functions. 从jQuery 1.5开始,错误设置可以接受函数数组。 Each function will be called in turn. 每个函数将依次调用。 Note: Prior to jQuery 1.5, this handler was not called for cross-domain script and JSONP requests. 注意:在jQuery 1.5之前,没有针对跨域脚本和JSONP请求调用此处理程序。 This is an Ajax Event 这是一个Ajax事件

jQuery has a very good documentation. jQuery有一个很好的文档。 The docs should be the first place to look at, for questions like yours. 对于像您这样的问题,文档应该是第一个查看的地方。 If you encounter problems while implementing jQuery you are welcome to ask at SO. 如果在实现jQuery时遇到问题,欢迎在SO处提问。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM