jQuery $.ajax()函数的错误消息源

在失败的情况下,代码如下:
error: function(msg)

msg来自哪里?

编辑:

我正在使用这个函数($ ajax)来调用WEB服务。所以如果谁投票选择这可以解释给我哪里的来自这将是巨大的!我在Web服务中设置它吗?如果是这样,怎么办?请不要复制和粘贴定义。

解决方法

从jquery文档:

error(XMLHttpRequest,textStatus,errorThrown) Function

A function to be called if the request fails. The function is passed three arguments:
– The XMLHttpRequest object,
– a string describing the type of error that occurred,and
– an optional exception object,if one occurred.
Possible values for the second argument (besides null) are “timeout”,“error”,“notmodified” and “parsererror”. This is an Ajax Event.

当你指出一个参数时,它将是xmlHttpRequestObject。你可以从中获得一些好的信息。可悲的是,绝大多数文档没有你正确设置。一个很好的认模板是:

error:function (xhRequest,errorText,thrownError)

你可以从xhRequest获得的一些好的信息是:

> .status:404:“未找到”,500:“服务器错误”。这有时可能是一个很大的帮助。
> .responseText是来自服务器的信息,在错误的情况下通常是无用的,但有时可能会有所帮助。

第二个值,一个字符串,有时是有帮助的。啊,我想可能的值在文档中提到。

第三个参数,每当我检查出来,一直是未定义的。我不认为这是有用的。

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: <span id=&quot...
jQuery 添加水印 <script src="../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...