在 jQuery 中发送到 .fail 的参数是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9847244/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 11:23:02  来源:igfitidea点击:

What are the parameters sent to .fail in jQuery?

jqueryajax

提问by Phillip Senn

I can't find the documentation on what the names of the three parameters are when $.ajaxfails.

我找不到有关$.ajax失败时三个参数名称的文档。

Right now, I'm just using:

现在,我只是在使用:

.fail(function(A, B, C) {

采纳答案by nathanjosiah

According to http://api.jquery.com/jQuery.ajax/the failcallback should be getting:

http://api.jquery.com/jQuery.ajax/fail回调应该得到:

jqXHR, textStatus, errorThrown

jqXHR, textStatus, errorThrown

same as error, but erroris deprecated:

与 相同error,但error已弃用:

Deprecation Notice: The jqXHR.success(), jqXHR.error(), and jqXHR.complete() callbacks will be deprecated in jQuery 1.8. To prepare your code for their eventual removal, use jqXHR.done(), jqXHR.fail(), and jqXHR.always() instead.

弃用通知:jqXHR.success()、jqXHR.error() 和 jqXHR.complete() 回调将在 jQuery 1.8 中弃用。要为最终删除代码做好准备,请改用 jqXHR.done()、jqXHR.fail() 和 jqXHR.always()。

回答by Olivier de Rivoyre

Here an example after looking for the same problem:

这是寻找相同问题后的示例:

this.GetOrderList = function (customerId) {
    var self = this;
    $.post('MySuperServer.aspx', { customerId: customerId })
    .done(function (dataStr) {
        var orderList = jQuery.parseJSON(dataStr);
        self.process(orderList);
    })
    .fail(function (jqXHR, textStatus, error) {
        console.log("Post error: " + error);
    });
}

While debugging, I've got:

在调试时,我有:

  • jqXHRis a JS object
  • textStatusis "error"
  • erroris "Internal Server Error", it's the error message sent by the server.
  • jqXHR是一个 JS 对象
  • textStatus是“错误”
  • 错误是“内部服务器错误”,它是服务器发送的错误消息。