ptf
ptf

Reputation: 3370

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?

Upvotes: 5

Views: 4860

Answers (1)

Anthony Grist
Anthony Grist

Reputation: 38345

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

Upvotes: 7

Related Questions