WILL JQUERY AJAXSTOP() MAKE RECURSIVE CALLS ? IF SO, HOW TO STOP IT?

Ankita Pandey

Total Post:183

Points:1285
Posted by  Ankita Pandey
AJAX 
 3657  View(s)
Ratings:
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.

  1. AVADHESH PATEL

    Post:604

    Points:4228
    Re: Will jQuery ajaxStop() make recursive calls ? if so, how to stop it?

    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.

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!