Bug Tracker

Opened 14 years ago

Closed 12 years ago

Last modified 11 years ago

#3442 closed enhancement (fixed)

JSONP should provide abort method

Reported by: tr4nslator Owned by:
Priority: low Milestone: 1.5
Component: ajax Version: 1.3.2
Keywords: jsonp, ajax Cc:
Blocked by: Blocking:


As discussed here:


Currently, there's no easy way to abort a JSONP call once it's been fired, because no reference to the window-scoped callback function (or injected script tag) is returned. Just as an XHR request returns the XHR object, JSONP calls should return a handler that allows callback cancellation.

(It would be nice to see this implemented along with something like this too: http://dev.jquery.com/ticket/1863)

Attachments (1)

jsonabort.patch (3.4 KB) - added by morgan 14 years ago.
jsonp/script abort and timeout patch

Download all attachments as: .zip

Change History (13)

comment:1 Changed 14 years ago by flesler

Cc: tr4nslator flesler added
Component: unfilledajax
Owner: flesler deleted

Changed 14 years ago by morgan

Attachment: jsonabort.patch added

jsonp/script abort and timeout patch

comment:2 Changed 14 years ago by morgan

Here is patch to add aborts for JSONP and script call. Also adds timeout support as suggested in #1863

comment:3 Changed 14 years ago by jalexander

The complete() callback isn't invoked upon timeout. This can probably be fixed by adding a call to complete() at the end of the timeout function.

comment:4 Changed 13 years ago by john

Milestone: 1.31.4
Type: bugenhancement

comment:5 Changed 13 years ago by Nichtich

I am waiting for this feature for more than a year. It's milestone is set to 1.4 but apparently is is not fixed in jQuery 1.4. There is a plugin that can be used instead: http://code.google.com/p/jquery-jsonp/

comment:6 Changed 13 years ago by jasondavies

When testing JSONP it seems the callbacks are executed in the order the JSONP requests were made. It's easy to see why, because the browser will execute <script> tags in order. This is problematic when early JSONP calls may take longer than later ones though. An abort() method would be very handy to stop these earlier (and no longer needed) calls from blocking later ones.

My particular use case is an autocomplete field that needs to run on any site (hence JSONP). The early calls tend to take longer because they produce more results e.g. all places starting with "L". Later ones are faster e.g. all places starting with "Londo".

comment:7 Changed 12 years ago by dmethvin

Unless I understand the patch incorrectly, this change does not truly abort the request. Instead, it simply sets a flag that tells the request it was aborted *once it returns* if it takes more than the timeout period. That is an important difference because the request is still "in flight" after being aborted and is taking up one of the connections to that domain.

IE6/7 in particular only allows two connections per domain by default. Subsequent JSONP requests to that domain will queue until the browsers gives up on the "aborted" requests. http://msdn.microsoft.com/en-us/library/cc304129%28VS.85%29.aspx

comment:8 Changed 12 years ago by SlexAxton

Milestone: 1.41.5
Priority: majorlow
Status: newopen

There is additional discussion in the W3C on the order of script execution upon dynamic insertion. It may be wise to wait for that. It may be worthwhile to add the async attribute to the scripts that are injected with jsonp. That may already solve some ordering issues.

comment:9 Changed 12 years ago by Rick Waldron

Keywords: ajaxrewrite added

comment:10 Changed 12 years ago by jaubourg

Resolution: fixed
Status: openclosed

You can abort any request, no matter its type in the new ajax.

comment:11 Changed 12 years ago by jitter

Cc: tr4nslator flesler removed
Keywords: ajaxrewrite removed

comment:13 Changed 11 years ago by Bogus Hawtsauce

In what version is this actually fixed?

In version 7.1 the abort function does not abort the actual call back for jsonp request, jquery fires off the error function like it should and its status is aborted, but the call is still active and holding an open connection to the server.

Note: See TracTickets for help on using tickets.