在$就实用JQuery的错误选项 [英] JQuery error option in $.ajax utility

查看:120
本文介绍了在$就实用JQuery的错误选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该文件表明错误:选项功能将提供:XHR例如,一个状态消息的字符串(在这种情况下总是错误)和一个可选的异常对象从XHR实例返回(书:JQuery的行动)。

The documentation indicates that the error: option function will make available: XHR instance, a status message string (in this case always error) and an optional exception object returned from the XHR instance (Book: JQuery in Action)

使用以下(在$就调用)我能确定我有一个parsererror和超时(因为我加了超时:选项)误差

Using the following (in the $.ajax call) I was able to determine I had a "parsererror" and a "timeout" (since I added the timeout: option) error

error: function(request, error){}

什么是你在错误选项评估其他的东西?你是否包含可选的异常对象?

What are other things you evaluate in the error option? do you include the optional exception object?

编辑:的答案之一,表示所有的回传失误...了解更多关于什么是价值(调试)在XHR实例和异常对象将是有益的。

one of the answers indicates all the return errors...learning more about what is of value (for debugging) in the XHR instance and exception object would be helpful

这是一个完整的$。阿贾克斯电话:

This is a complete $.ajax call:

$.ajax({
 type: "post",
 url: "http://myServer/cgi-bin/broker" ,
 dataType: "text",
 data: {
 '_service' : 'myService',
 '_program' : 'myProgram',
 'start' : start,
 'end' : end
 },
 beforeSend: function() {
  $("#loading").removeClass("hide");
 },
 timeout: 5000,
 error: function(request,error) {
  $("#loading").addClass("hide");
  if (error == "timeout") {
   $("#error").append("The request timed out, please resubmit");
  }
  else {
   $("#error").append("ERROR: " + error);
  }
  },
  success: function(request) {
   $("#loading").addClass("hide");
   var t = eval( "(" + request + ")" ) ;
  } // End success
}); // End ajax method

感谢您的输入

Thanks for the input

推荐答案

看着jQuery的源头code,有四个返回状态,在additon为成功

Looking at the jQuery source code, there are four returned statuses, in additon to success:

  • 超时 - 当您指定 超时超出
  • 错误 - HTTP错误,如404
  • notmodified - 当要求 自去年资源未被修改 要求
  • parsererror - 当XML / JSON响应 坏
  • timeout - when your specified timeout is exceeded
  • error - http error, like 404
  • notmodified - when requested resource was not modified since last request
  • parsererror - when an xml/json response is bad

这篇关于在$就实用JQuery的错误选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆