jQuery post respond with readyState:0, status:0

后端 未结 4 629
予麋鹿
予麋鹿 2020-12-10 15:15

all. I am using a jquery version 1.6.2. I do a ajax call like this:

  var jqxhr = $j.post(myPHP, function() {
          alert(\"success\");
        })
               


        
相关标签:
4条回答
  • 2020-12-10 15:28

    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.

    0 讨论(0)
  • 2020-12-10 15:31

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

    0 讨论(0)
  • 2020-12-10 15:32

    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

    0 讨论(0)
  • 2020-12-10 15:33

    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"); });
    
    0 讨论(0)
提交回复
热议问题