admin管理员组文章数量:1404469
$.ajax({
url: urlString,
dataType: "json",
type: "GET",
success: function (data) {
alert(data);
},
error: function (jqXHR, exception) {
if (jqXHR.status === 0) {
alert('Not connect.\n Verify Network.');
} else if (jqXHR.status == 404) {
alert('Requested page not found. [404]');
} else if (jqXHR.status == 500) {
alert('Internal Server Error [500].');
} else if (exception === 'parsererror') {
alert('Requested JSON parse failed.');
} else if (exception === 'timeout') {
alert('Time out error.');
} else if (exception === 'abort') {
alert('Ajax request aborted.');
} else {
alert('Uncaught Error.\n' + jqXHR.responseText);
}
}
});
This is my javascript file that im using to access some information from a server. The urlString is supplied and is correct. What I did was download the .json from the server that I was retrieving and accessed it locally on my puter. When I go to access the file from the server I keep getting jqXHR.status==0 error. I'm not sure how to fix that because I can't see anything wrong with my code.
Can someone point me in the right direction to fix my error?
$.ajax({
url: urlString,
dataType: "json",
type: "GET",
success: function (data) {
alert(data);
},
error: function (jqXHR, exception) {
if (jqXHR.status === 0) {
alert('Not connect.\n Verify Network.');
} else if (jqXHR.status == 404) {
alert('Requested page not found. [404]');
} else if (jqXHR.status == 500) {
alert('Internal Server Error [500].');
} else if (exception === 'parsererror') {
alert('Requested JSON parse failed.');
} else if (exception === 'timeout') {
alert('Time out error.');
} else if (exception === 'abort') {
alert('Ajax request aborted.');
} else {
alert('Uncaught Error.\n' + jqXHR.responseText);
}
}
});
This is my javascript file that im using to access some information from a server. The urlString is supplied and is correct. What I did was download the .json from the server that I was retrieving and accessed it locally on my puter. When I go to access the file from the server I keep getting jqXHR.status==0 error. I'm not sure how to fix that because I can't see anything wrong with my code.
Can someone point me in the right direction to fix my error?
Share Improve this question asked May 22, 2014 at 9:12 user3664250user3664250 312 gold badges2 silver badges8 bronze badges 2- Related, possible duplicate: jquery ajax jqXHR.status is always 0. – Frédéric Hamidi Commented May 22, 2014 at 9:18
- 1 no I've read that post and it is related but there is no action for the page. It runs when the document is ready. – user3664250 Commented May 22, 2014 at 9:22
3 Answers
Reset to default 2The reason that you get different status codes is that the file isn't fetched with the http:
protocol but with the file:
protocol. It's natural that different protocols have different status codes.
You simply need to have different behaviour depending on where you fetch the file from.
There is a Mozilla bug report about this, which is marked as invalid because this is considered to be the correct result.
JQXHR Status: 0
Reason: Request does not cancel when the Ajax function is called.
Resolution: Simply add return false;
after calling the function, i.e
OnClientClick="AJAXMethod(); return false;"
In my case Chrome's 'Network throttling' was set to 'Offline'.
I have removed this error by going to 'Ctrl+Shift+I' > 'Network' tab > click on 'More network conditions...' icon > select 'Network throttling' to 'No throttling'.
本文标签: javascriptAjax jqXHRstatus0 fix errorStack Overflow
版权声明:本文标题:javascript - Ajax jqXHR.status==0 fix error - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744801758a2625904.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论