1

when users click certain links on my app it makes ajax requests... What I want to do is on every main click, abort all existing ajax requests either current or pending. Is this possible?

The reason why is requests are getting out of sync. Meaning if a user clicks on a project, which should load tasks. If they then click on another project, the first click's tasks are being populated.

Thanks

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
AnApprentice
  • 108,152
  • 195
  • 629
  • 1,012

2 Answers2

0

Simply keep a global variable which stores the most recent ajax request and then abort it before making the next request.

James Montagne
  • 77,516
  • 14
  • 110
  • 130
-1

When we abort an variable-cum-ajaxRequest using variable.abort(); it is permanently disabled and cannot be used to create another request in the future.

So to avoid this we can use dynamic variables window["var"+i] and increase the value of i everytime an new request is made.

Then at the time a request is to be cancelled use window["var"+(i-1)].abort();

Taryn
  • 242,637
  • 56
  • 362
  • 405