WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

#32628 closed task (blessed) (fixed)

Allow wp.ajax.send() requests to be stopped via abort()

Reported by: westonruter Owned by: wonderboymusic
Milestone: 4.3 Priority: normal
Severity: normal Version: 3.6
Component: General Keywords: has-patch commit
Focuses: javascript Cc:

Description

For Menu Customizer (#32576) we have a search box that triggers after a delay triggers an Ajax request via wp.ajax.post(). The promise that this returns has done(), fail(), and always() handlers added to it. We want the done() to not happen if the user starts typing again and another Ajax request is initiated. In jQuery's Ajax API, the jqXHR has an abort() method which stops the HTTP request and causes the fail() to execute. However, in the wp.ajax.send() (and wp.ajax.post()) wrappers around jqXHR, this abort() method is not made available, and so there is no way to stop a WP Ajax request presently. I propose we add the abort() method. This was given the thumbs up: https://wordpress.slack.com/archives/core/p1433964230002347

Attachments (1)

Change History (4)

#1 @westonruter
4 years ago

  • Keywords commit added

#2 @wonderboymusic
4 years ago

this is fine, I changed the naming case to match jQuery:
https://github.com/jquery/jquery/search?utf8=%E2%9C%93&q=xhr&type=Code

I'll commit this.

#3 @wonderboymusic
4 years ago

  • Owner set to wonderboymusic
  • Resolution set to fixed
  • Status changed from new to closed

In 32747:

Add an abort class method to the Promise instance returned by wp.ajax.send().

Props westonruter.
Fixes #32628.

Note: See TracTickets for help on using tickets.