-1

Consider I have 4 option like

  1. display Name
  2. display Age
  3. display Address
  4. display PhoneNo

On clicking of each option i am making an ajax request and pulling the appropriate details and displaying it. but the problem is for an instance i click on the display Name option the ajax request is sent immediately i click on the display Age option this triggers an ajax request and displays the data when the first request's response comes back it overwrites the data of the second request, So can i stop the previous ajax request(s). Thanks.

shivam
  • 16,048
  • 3
  • 56
  • 71
John Britto
  • 457
  • 1
  • 4
  • 19

2 Answers2

1

Use a variable to store a AJAX request:

var request = $.ajax({
    type: 'POST',
    url: 'someurl',
    success: function(result){}
});

AND abort the request before you call again the same AJAX function:

request.abort();

You could use an array keeping track of all pending ajax requests and abort them if necessary.

Ruprit
  • 733
  • 1
  • 6
  • 23
0

yes possible.

 var ajaxCall=$.ajax({
      -----
      ------
     });

then.You can use the following code, If you want reject of the ajax response

ajaxCall.abort()
Visva
  • 194
  • 1
  • 3
  • 11
  • Thanks, but if don't know the ajax request name like ("ajaxCall.abort()" ) how to abort all requests globally. – John Britto Jan 22 '15 at 12:31
  • this [link]:http://stackoverflow.com/questions/1802936/stop-all-active-ajax-requests-in-jquery may help you – Visva Jan 22 '15 at 12:38