jQuery ajax post 返回 501 错误代码
我们正在使用 jQuery(1.2.3) ajax post,并且偶尔会收到 12031/501 错误消息。
这个错误的原因可能是什么?
示例代码
jQuery.post('${pageContext.request.contextPath}/sample/someAction.do', jQuery("#form_name").serialize(), function(status){
//Some other code for checking the status......
}
表单有两个文本区域(一个禁用,一个启用)和一个复选框。还有一个提交按钮。
并且有一个ajax错误处理函数,用于处理12031/501类型的错误消息。有时会显示一个警告框,指出 ajax post 中发生错误。
$("#form_name").ajaxError(function(event, xhr, settings, exception) {
var errorMessage = "Error in ajax post -";
errorMessage += "\n\t url: " + settings.url;
errorMessage += "\n\t exception: " + exception + ((exception) ? " - " + exception.description : "");
errorMessage += "\n\t readyState: " + xhr.readyState;
errorMessage += "\n\t status: " + xhr.status;
errorMessage += "\n\t statusText: " + xhr.statusText;
errorMessage += "\n\t responseText: " + xhr.responseText;
errorMessage += "\n\t";
alert('Error occured in ajax post..........'+errorMessage);
});
仅当 ajax post 出现错误且错误代码为 12031(与服务器的连接已重置。)或 501/12152 时,才会显示此警告框。
现在我们可以看到另外一个错误代码是 12152(服务器返回了无效或无法识别的响应。)。
这是 jQuery(1.2) 问题还是环境中的其他问题还是 IE7?
如果我们重新提交请求,那么它就可以正常工作。现在我们告诉用户重新提交请求以便保存数据。
现在这不是一个可行的解决方案。而且这个问题偶尔会出现。
任何有关这些错误代码的见解将不胜感激。
谢谢
We are using jQuery(1.2.3) ajax post and we are getting 12031/501 error message sporadically.
What could be the reason of this error?
Sample code
jQuery.post('${pageContext.request.contextPath}/sample/someAction.do', jQuery("#form_name").serialize(), function(status){
//Some other code for checking the status......
}
Form has two textarea(one disabled, one enabled) and a check box. And a submit button.
And there is one ajax error handling function which is for handling 12031/501 kind of error msg. Which sometimes shows a alert box saying that error happen in ajax post.
$("#form_name").ajaxError(function(event, xhr, settings, exception) {
var errorMessage = "Error in ajax post -";
errorMessage += "\n\t url: " + settings.url;
errorMessage += "\n\t exception: " + exception + ((exception) ? " - " + exception.description : "");
errorMessage += "\n\t readyState: " + xhr.readyState;
errorMessage += "\n\t status: " + xhr.status;
errorMessage += "\n\t statusText: " + xhr.statusText;
errorMessage += "\n\t responseText: " + xhr.responseText;
errorMessage += "\n\t";
alert('Error occured in ajax post..........'+errorMessage);
});
This alert box will display only when there is error on ajax post and the error code is 12031(The connection with the server was reset.) or 501/12152.
Now there is one more error code we are able to see is 12152(The server returned an invalid or unrecognized response.).
Is this a jQuery(1.2) issue or something else in environment or is it IE7?
If we resubmit the request then it is working fine. For now we are telling user to resubmit the request so that data can be saved.
Now this is not a viable solution. And this problem occurs sporadically.
Any insight on those error codes would really be appreciated.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Ajax 向服务器发出请求,服务器返回 501。因此,看看服务器返回 501 的原因。
并且您应该确保发出的 XMLHttpRequest 是正确的 - 显然是正确的 url、参数等。
Ajax does a request to the server, the server returns the 501. Therefore, look at why the server returns 501.
And you should make sure the XMLHttpRequest made was proper - right url, arguments, etc obviously.
501 错误是因为您使用的服务器(大概是 simpleHTTPServer 之类的服务器)不支持 POST 请求。
要解决该错误,您需要使用支持 POST 请求的服务器,例如 apache
The 501 error is because the server you are using (presumably something like simpleHTTPServer) doesn't support POST requests.
To resolve that error you need to use a server that supports POST requests like apache