jQuery的AJAX误差函数具有下列参数:
错误(XMLHtt prequest,textStatus,errorThrown)
什么是最好的跨浏览器的方式来获得响应主体?
请问这项工作(可靠在所有浏览器)?
$。阿贾克斯({
错误:功能(HTTP){
警报(http.responseText);
}
});
解决方案
有一个隐藏的功能,可以从XHR istance提取数据:
VAR的responseText = $ .httpData(XHR)
![ajax报错get,使用七牛CDN导致ajax评论报错 error get from image source failed E405 落格博客...](/d/file/2023/09-15/7c9d67f7cf96da0996883f504e55e105.png)
如果您通过JSON
作为第二个参数,它将把响应作为JSON字符串。
请注意,你可能会得到一个错误,因为没有反应(例如网络问题)。请确保您覆盖这种情况下也是如此。另外,我认为(不知道)的jQuery的调用错误
处理程序,如果服务器返回一个 4XX
或 5XX
状态。
jQuery's AJAX error function has the following parameters:
error(XMLHttpRequest, textStatus, errorThrown)
What's the best cross-browser way to get the response body?
Does this work (reliably in all browsers)?
$.ajax({
error: function(http) {
alert(http.responseText);
}
});
解决方案
There is a hidden function that can extract the data from XHR istance:
var responseText = $.httpData(xhr)
If you pass "json"
as a second parameter it will treat the response as a JSON string.
Note that you might get an error because there is no response (network problem for example). Make sure you cover that case as well. Also, I believe (not sure) that jQuery invokes the error
handler if the server returns a 4xx
or 5xx
status.
相关推荐
最新文章