I cannot stop ajax request using jQuery and abort () function

My jQuery is below:

var x = $.ajax({ dataType: "jsonp", url: "https://ajax.googleapis.com/ajax/services/search/images?q=google&v=1.0", success: function(msg){ alert( "Jsonp data: " + msg ); } }); alert(x); // x is undefined // x.abort()​​ 

You can try this code here: http://jsbin.com/iyile3/2/edit

I want to stop this ajax request and stop this successful ajax request function.

But I get that "x" is undefined, I think I am not stopping this ajax request and its success function.

So can someone help me?

Many thanks!

+7
jquery jsonp ajax abort
source share
2 answers

Well, that makes sense.

A jsonp call is not an ordinary XMLHttpRequest (which usually returns .ajax ()). This will not work, since you cannot snatch the same origin policy .

JSON-Padding works with dynamic tag insertion script. This way jQuery just creates a <script> on your site and loads the data. There is no XHR object.

I don’t think there is a way to terminate such a request ahead of schedule, but I hope that someone will correct me if I am mistaken.

+9
source share

I think the documentation may be a little misleading. When using JSONP, an AJAX request is not requested. In this case, the ajax function returns undefined instead of the XMLHTTPRequest object.

+4
source share

All Articles