调试jQuery的AJAX功能 [英] Debugging Jquery ajax function
问题描述
JS code:
$.ajax({
type: 'POST',
url: 'http://localhost/MyServiceDir/Service.asmx/Foo',
contentType: 'application/json; charset=utf-8',
data: jsonData,
success: function (msg) {
alert("good");
},
error: function (xhr, status) {
switch (status) {
case 404:
alert('File not found');
break;
case 500:
alert('Server error');
break;
case 0:
alert('Request aborted');
break;
default:
alert('Unknown error ' + status);
}
}
});
我得到未知错误错误。我如何到达这条底线?我想知道是什么错误实际上是。谢谢!
I get "unknown error error". How do I get to the bottom of this? I would like to know what the error actually is. Thanks!
推荐答案
状态参数只包括为什么会失败 - 超时,错误,等等......为了获得状态code,你需要检查响应对象: xhr.status
The "status" parameter only includes why it failed -- timeout, error, etc... To get the status code you need to check the response object: xhr.status
请参阅 http://www.w3.org/TR/XMLHttprequest /#响应了解详细信息。
如果您收到500内部服务器错误的是的所有,你会从阿贾克斯得到。你必须检查你的应用程序或服务器日志。这可能是一个语法错误或或库错误或别的东西沿着这些线路。
If you are getting "500 Internal Server Error" that is all you are going to get from ajax. You will have to check your application or server logs. This could be a syntax error or or library error or something else along those lines.
这篇关于调试jQuery的AJAX功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!