Bug Tracker

Modify

Ticket #2688 (closed enhancement: duplicate)

Opened 5 years ago

Last modified 5 years ago

beforeSend should be able to cancel the Ajax call

Reported by: yehuda Owned by: yehuda
Priority: major Milestone: 1.2.4
Component: ajax Version: 1.2.3
Keywords: Cc:
Blocking: Blocked by:

Description

There's no current way to stop an Ajax call based on certain criteria. For instance, it would be nice to be able to cache the results of Ajax calls, and have them fire the success function for subsequent calls after the first success.

Change History

comment:1 Changed 5 years ago by yehuda

  • Owner set to yehuda
  • Status changed from new to assigned
  • Component changed from core to ajax

I am patching $.ajax to allow return false from beforeSend, as well as to pass the $.ajax options as the second parameter to beforeSend.

comment:2 Changed 5 years ago by scott.gonzal

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

Fixed in [5253].

comment:3 Changed 5 years ago by flesler

Hi Yehuda It's really an unnecesary change but... you could simply do:

if ( s.beforeSend && s.beforeSend(xml, s) === false )
	  return false;

Seems clearer to me, and it's shorter.

comment:4 Changed 5 years ago by joern

  • Status changed from closed to reopened
  • Resolution fixed deleted

comment:5 Changed 5 years ago by joern

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

Improved in [5281], added test.

comment:6 Changed 5 years ago by joern

  • Status changed from closed to reopened
  • Resolution fixed deleted

comment:7 Changed 5 years ago by joern

Turned out that $.ajax increased the active requests counter via jQuery.active++ without ever decreasing that when cancelling via beforeSend, preventing ajaxStop to get triggered when appropiate. Also the opened socket wasn't closed.

comment:8 Changed 5 years ago by joern

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

Fixed in [5282].

comment:9 Changed 5 years ago by joern

  • Status changed from closed to reopened
  • Resolution fixed deleted

comment:10 Changed 5 years ago by joern

  • Status changed from reopened to closed
  • Resolution set to duplicate

On abort via beforeSend, ajaxStop is never called, even when ajaxStart was triggered.

Closing this ticket as duplicated of #2935, see patch there.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.