Home > DeveloperSection > Forums > Will jQuery ajaxStop() make recursive calls ? if so, how to stop it?
Ankita Pandey
Ankita Pandey

Total Post:183

Points:1285
Posted on    May-18-2013 1:36 AM

 AJAX AJAX 
Ratings:


 1 Reply(s)
 2810  View(s)
Rate this:
Hi Everyone!

I'm showing Ajax login form for various user action in my portal, once successfully login I want to update some div's for that I'm using following code,

 $(document).ajaxStop(function(){

        $.get($(location).attr('href'),function(html){
        var $html = $(html);
        $('#topBar').html($html.find('#topBar'));
        $('#commentsForm').html($html.find('#commentsForm'));
        });
  });
Will above code leads to any recursive Ajax calls ? currently its working as expected but I want to know it clearly.

Update:

I kept log at end of the ajaxStop then it printing log message recursively then it shows clearly that above code making recursive calls.



AVADHESH PATEL

Total Post:604

Points:4228
Posted on    May-18-2013 8:34 AM

Hi Ankita!

I think this will cause recursion. After all the other AJAX calls complete, this handler will call. It will start a new AJAX call with $.get(), and when that completes it will trigger the handler, which will call $.get(), and so on.

To prevent this, you can do:

$.ajaxSetup( { global: false } );
to prevent global AJAX handlers from running. Or replace $.get() with the equivalent $.ajax() call, and use global: false in its options argument.


Don't want to miss updates? Please click the below button!

Follow MindStick