使用ajax检测HTTP错误
我正在使用 ajax 调用来检索一些 HTML 数据。在某些情况下,我可能会收到 HTTP 错误 403(由于某些 IE bug 在 IE 上使用 ajax 调用时遇到 403 错误, 带有正斜杠抛出 403 的哈希片段IE 中的 AJAX 请求错误)。
出于错误处理的目的,我想捕获发生的错误并相应地显示一些错误消息。
我该怎么做?
也许像
$.ajax({
type : 'POST',
data : data,
cache : false,
url : url,
dataType : 'html'
success : function(){
//if HTTP response is ok, diplay data
//else if HTTP response gets 403 error, display some other message
}
});
I'm using ajax calls to retrieve some HTML data. In certain cases, there are chances that I may get HTTP error 403 (because of some IE bug Encountering 403 error while using ajax call on IE, Hash fragments with forward-slash throwing 403 errors with AJAX requests in IE).
For error handling purposes, I want to catch what error has occured and accordingly display some error message.
How do I do that?
Maybe something like
$.ajax({
type : 'POST',
data : data,
cache : false,
url : url,
dataType : 'html'
success : function(){
//if HTTP response is ok, diplay data
//else if HTTP response gets 403 error, display some other message
}
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
引用文档:
To quote the documentation: