Bug Tracker

Opened 5 years ago

Closed 5 years ago

#15160 closed bug (migrated)

ajaxError and ajaxComplete firing twice upon abort

Reported by: Dwelle Owned by:
Priority: low Milestone: None
Component: ajax Version: 1.11.1
Keywords: ajax, abort, event Cc:
Blocked by: Blocking:

Description

Aborting jqXHR objects inside ajaxSend results in ajaxError and ajaxComplete callbacks being called twice. On first execution, jqXHR's status is "abort", on second execution, it throws TypeError: Cannot read property 'send' of undefined .

JSFiddle: http://jsfiddle.net/LK2g3/

tested on Chrome 35, FF 30, jQuery 1.9.1, 1.11.1, 2.1.1

Change History (3)

comment:1 Changed 5 years ago by dmethvin

Priority: undecidedlow
Status: newopen
Version: 1.9.11.11.1

Looks like this has been around for a while. Aborting happens synchronously and cleans up the request to avoid memory bloat. Then when it gets back from the ajaxSend it actually tries to send the request and the XHR object was blown out from under it.

Aborting the request doesn't make a lot of sense at that point, you can see from the XHR spec that it's pretty much a no-op if called before a .send(). So it seems more appropriate to have ajaxSend indicate that it doesn't want the request to proceed in some other way. The concern I'd have with making a change there would be compat. At least we know aborting doesn't currently work.

I'll mark this open for discussion.

comment:2 Changed 5 years ago by Azriel

I've opened a PR with a suggested solution to this here: https://github.com/jquery/jquery/pull/1619

comment:3 Changed 5 years ago by m_gol

Resolution: migrated
Status: openclosed
Note: See TracTickets for help on using tickets.