I'm making ajax request to server on another domain but I don't actially need its response, just to know that it got my request. When everything is ok, in Chrome Developer Tools (Header status) it says «canceled» and console writes «XMLHttpRequest cannot load» but server gets my requests. When server is down then header status is not a number but just «failed». Trying to catch this critical difference on JS I get XHR status 0 in both cases.
Asked
Active
Viewed 251 times
1 Answers
0
I'm making ajax request to server on another domain
You can't make an ajax request to a different domain, due to same-origin policy. You want to look at JSONP, which essentially writes out a <script>
tag for a remote URL.
Detecting success/error with JSONP calls is tricky, it doesn't work like typical ajax calls at all. Ideally you want the remote server to call a callback function on your page, as the above link describes.
If you don't control the other domain, you can attempt to detect errors by using a timeout. Here is a post discussing the jQuery timeout argument for this, though you could certainly implement your own timeout with raw javascript as well.
-
Bacause I don't control server's responses a timeout limitation is good-enough (and apparently the only one) solution in my case. Thank you! – mu3 Apr 05 '13 at 04:00