Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Ajax requests are getting cancelled without being sent

I am trying to hook up a script to Microsoft's World-Wide Telescope app. The latter listens on port 5050 for commands. It is running on the same machine as the browser (Chrome right now, but as far as I can tell the behavior is the same with Firefox 7 and IE 9).

I am sending a "Access-Control-Allow-Origin: *" header with the original html file to try to eliminate XSS restrictions as my problem.

My code to access WWT is as follows:

$.ajax({     type: 'POST',     url: url,     data: data,     crossDomain: true,     success: success,     dataType: dataType }); 

url in this case is "http://127.0.0.1:5050/layerApi.aspx?cmd=new&..." (obviously ... is shorthand here for some additional parameters).

Looking at the network diagnostics in Chrome, I can see this:

Request URL:http://127.0.0.1:5050/layerApi.aspx?cmd=new&... Request Headersview source Accept:application/xml, text/xml, */*; q=0.01 Content-Type:application/x-www-form-urlencoded Origin:http://gwheeler4 Referer:http://gwheeler4/conceptconnect.html User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.186 Safari/535.1 

The request is going out - I see WWT make a new layer. However, I don't get a callback. If I add an error callback that gets called, but the error property on the jqXHR object is just "error" and status is 0. If I look at the network request in Chrome I see "(cancelled)" as the status and no response.

If I take that same URL and paste it in a new browser tab, I can see that the response is the expected XML.

Of course, a difference here is that this is a GET not a POST, but I've tried that in my script and it makes no difference.

I'm pretty stumped by this and would appreciate any fresh ideas.

like image 793
Graham Wheeler Avatar asked Sep 28 '11 01:09

Graham Wheeler


People also ask

Why is XHR request Cancelled?

XHR requests are cancelled and re-issued if they don't return in 30 seconds · Issue #6426 · cypress-io/cypress · GitHub.

Why does AJAX call fail?

ajax method lets you set a timeout in milli seconds. When a timeout happens, The fail callback is called, with errorThrown set to "timeout". The request is aborted, meaning that even if the response arrives later on, your done callback is not called by jQuery.

What triggers AJAX success?

AJAX success is a global event. Global events are triggered on the document to call any handlers who may be listening. The ajaxSuccess event is only called if the request is successful. It is essentially a type function that's called when a request proceeds.

Which method cancels the current request?

abort() method aborts the request if it has already been sent. When a request is aborted, its readyState is changed to XMLHttpRequest.


1 Answers

If anyone else runs into this, the issue we had was that we were making the ajax request from a link, and not preventing the link from being followed. So if you are doing this in an onclick attribute, make sure to return false; as well.

like image 131
Kazetsukai Avatar answered Sep 17 '22 02:09

Kazetsukai