简体   繁体   English

jQuery.ajax认为哪些响应是“成功”?

[英]What responses does jQuery.ajax consider to be “success”?

I have a jQuery AJAX post request that is unexpectedly triggering the error callback instead of success . 我有一个jQuery AJAX post请求,它意外地触发了error回调而不是success One random suspicion I have is the 302 status code it is receiving, although that may be wrong. 我有一个随机的怀疑是它正在接收的302状态代码,尽管这可能是错误的。

I looked at the documentation , but I feel like one thing is a bit unclear: What is jQuery's definition of a successful request? 我查看了文档 ,但我觉得有一点不清楚:jQuery对成功请求的定义是什么?

If the response is between 199 and 300 ( >= 200 and < 300 ) or equal to 304 and the responseText can be successfully converted to the dataType that you provide (text by default), it is considered a successful request. 如果响应介于199和300之间(> = 200且<300)或等于304,并且responseText可以成功转换为您提供的dataType(默认为文本),则会将其视为成功请求。

For example, if you return JSON and you get a 200 response status but it fails, it is more than likely a JSON parser problem meaning your JSON is not valid. 例如,如果您返回JSON并且您获得200响应状态但它失败,则很可能是JSON解析器问题意味着您的JSON无效。

If you are returning HTML or XML and it fails with a 200 response status, the responsetext couldn't be converted to HTML or XML respectively (commonly happens in IE with invalid html/xml) 如果您返回HTML或XML并且它以200响应状态失败,则无法将responsetext转换为HTML或XML(通常在IE中使用无效的html / xml)

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

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