Bug Tracker

Ticket #3442 (closed enhancement: fixed)

Opened 6 years ago

Last modified 2 years ago

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:
Blocking: Blocked by:

Description

As discussed here:

 http://groups.google.com/group/jquery-dev/browse_thread/thread/e313b7f8ae5948cb

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

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

Change History

comment:1 Changed 6 years ago by flesler

  • Cc tr4nslator, flesler added
  • Owner flesler deleted
  • Component changed from unfilled to ajax

Changed 6 years ago by morgan

jsonp/script abort and timeout patch

comment:2 Changed 6 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 6 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 5 years ago by john

  • Version changed from 1.2.6 to 1.3.2
  • Type changed from bug to enhancement
  • Milestone changed from 1.3 to 1.4

comment:5 Changed 4 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 4 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 4 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 4 years ago by SlexAxton

  • Priority changed from major to low
  • Status changed from new to open
  • Milestone changed from 1.4 to 1.5

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 4 years ago by rwaldron

  • Keywords jsonp,ajax,ajaxrewrite added; jsonp ajax removed

comment:10 Changed 4 years ago by jaubourg

  • Status changed from open to closed
  • Resolution set to fixed

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

comment:11 Changed 4 years ago by jitter

  • Cc tr4nslator, flesler removed
  • Keywords jsonp,ajax added; jsonp,ajax,ajaxrewrite removed

comment:13 Changed 2 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.