Why is AJAX returning HTTP status code 0?

后端 未结 20 2788
野的像风
野的像风 2020-11-22 06:39

For some reason, while using AJAX (with my dashcode developed application) the browser just stops uploading and returns status codes of 0. Why does this happen?

相关标签:
20条回答
  • 2020-11-22 07:11

    In my experience, you'll see a status of 0 when:

    • doing cross-site scripting (where access is denied)
    • requesting a URL that is unreachable (typo, DNS issues, etc)
    • the request is otherwise intercepted (check your ad blocker)
    • as above, if the request is interrupted (browser navigates away from the page)
    0 讨论(0)
  • 2020-11-22 07:13

    It is important to note, that ajax calls can fail even within a session which is defined by a cookie with a certain domain prefixed with www. When you then call your php script e.g. without the www. prefix in the url, the call will fail and viceversa, too.

    0 讨论(0)
  • 2020-11-22 07:13

    In my case, I was getting this but only on Safari Mobile. The problem is that I was using the full URL (http://example.com/whatever.php) instead of the relative one (whatever.php). This doesn't make any sense though, it can't be a XSS issue because my site is hosted at http://example.com. I guess Safari looks at the http part and automatically flags it as an insecure request without inspecting the rest of the URL.

    0 讨论(0)
  • 2020-11-22 07:14

    In my troubleshooting, I found this AJAX xmlhttpRequest.status == 0 could mean the client call had NOT reached the server yet, but failed due to issue on the client side. If the response was from server, then the status must be either those 1xx/2xx/3xx/4xx/5xx HTTP Response code. Henceforth, the troubleshooting shall focus on the CLIENT issue, and could be internet network connection down or one of those described by @Langdon above.

    0 讨论(0)
  • 2020-11-22 07:16

    "Accidental" form submission was exactly the problem I was having. I just removed the FORM tags altogether and that seems to fix the problem. Thank you, everybody!

    0 讨论(0)
  • 2020-11-22 07:17

    This article helped me. I was submitting form via AJAX and forgotten to use return false (after my ajax request) which led to classic form submission but strangely it was not completed.

    0 讨论(0)
提交回复
热议问题