i am making simple autosuggestion (autocompleter) plugin with jQuery. Unfortunately i have to use jsonp. It is ok and it works, but when i am aborting request it will throw error.
Uncaught TypeError: Property 'jQuery171036404498340561986_1330693563756' of object [object Window] is not a function
There is code
if(xhr) {xhr.abort()};
xhr = $.ajax({
url: "someurl/getmedata",
type: 'get',
dataType: 'jsonp',
data: {q: "query"},
success: function(results) {},
error: function() {}
})
Classic way with json, xml or other request works fine.
Anny suggestion?
JSONPdoes not useXMLHTTPRequestbut actually creates a<script>tag within the document to be able to make the cross-domain requests.You simply cannot abort JSONP requests.
It is stated in the $.ajax() documentation:
As for jQuery 1.5+, previously was returning the XHR object from $.ajax(), now it returns a superset jqXHR object which encapsulates the XHR object.
So it returns an object but some functionnalities are actually not available, like .abort().
The plugin jQuery-JSONP seems to offer the possibility to manually abort JSONP requests. I haven’t used it myself but it’s worth giving it a try.