HelloMoon
HelloMoon

Reputation:

How to intercept all jquery ajax events?

I have an big JavaScript application with a lot of ajax in there (third-party script). Now I need to intercept all ajax events, i.e. when a message from server comes back with transport text or message, i want this text / message to do replacements.

problem: i tried with this, but it never reacts on any ajax event. It's from the jquery examples page and this #msg thing looks like a placeholder for something:

$("#msg").ajaxSuccess(function(evt, request, settings){
            alert('ajax event');
            $(this).append("<li>Successful Request!</li>");
});

Upvotes: 2

Views: 2094

Answers (1)

dano
dano

Reputation: 5630

Your syntax looks correct. I've triple checked the syntax.. and it seems fine. You mentioned that you are using 3rd party ajax calls... the .ajaxSuccess() will only trigger if you're using jQuery's ajax calls.. like $.post, $.get or $.ajax.

If your ajax calls are 3rd party calls you're going to have to change over all your other ajax calls to using jQuery methods.

I hope this helps? It may not be correct at all.

Upvotes: 1

Related Questions