Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery ajaxComplete called every time?

I have a question regarding .ajaxComplete().

Lets say I do this:

// Register an ajaxComplete (pseudo code ish)
$('#someId').ajaxComplete(function () {
    if (ajaxCompleted == isAjaxImWaitingForToComplete) {
        // something something
    }
});

Then this will be called every time an ajax task finishes. Is there a way to make it only be called once, then unregister? Could I add $('#someId').unbind(); at the bottom of the function inside the ajaxComplete?

like image 205
ptf Avatar asked May 04 '12 09:05

ptf


People also ask

What is the main difference between the ajaxStop and ajaxComplete?

This may not seem different when you're sending one ajax request at a time, but imagine that the network happened to slow down after you send request A and, when request B is sent 5 seconds later it comes back earlier than request A... then ajaxStop will only be triggered once after request A returns while ajaxComplete ...

How do you check if all AJAX calls are completed?

jQuery ajaxStop() Method The ajaxStop() method specifies a function to run when ALL AJAX requests have completed. When an AJAX request completes, jQuery checks if there are any more AJAX requests. The function specified with the ajaxStop() method will run if no other requests are pending.

How do I make jQuery wait for an AJAX call to finish before it returns?

If you don't want the $. ajax() function to return immediately, set the async option to false : $(". my_link").

How would you fire a callback when any AJAX request on a page has completed?

The ajaxComplete() method specifies a function to be run when an AJAX request completes. Note: As of jQuery version 1.8, this method should only be attached to document. Unlike ajaxSuccess(), functions specified with the ajaxComplete() method will run when the request is completed, even it is not successful.


1 Answers

The .ajaxComplete() function binds a handler for the ajaxComplete AJAX event, so calling .unbind('ajaxComplete'); should work.

like image 99
Anthony Grist Avatar answered Oct 06 '22 09:10

Anthony Grist