jQuery post respond with readyState:0, status:0

限于喜欢 提交于 2019-11-28 11:13:57
user1775765

For me this problem was caused by a cross-domain issue. So I had a local html file (c:\test.html) and tried to get data from a server (localhost/servlet). When putting html on the server - the problem was gone.

If the browser switches the web page while an XHR request is still in progress (the user clicked a link, the back button, …), this XHR request will be cancelled with exactly your error.

Have a look at the following blog post, where the issue is explained in depth: http://bartwullems.blogspot.de/2012/02/ajax-request-returns-status-0.html

You forgot to tell jQuery that the server is returning JSON:

   var jqxhr = $j.post(myPHP, function() {
           alert("success");
         }, "json") // here
        .success(function() { alert("second success"); })
        .error(function(data) { alert(JSON.stringify(data)); })
        .complete(function() { alert("complete"); });
user007

In my case, it was not due to Cross domain. I was not using e.PreventDefault(). See here

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!