2

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>"); }); 

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

7 Comments

what does that "#msg" thing do in first line? I don't have to replace it with something?
#msg refers to a control that has an id of "msg" (case sensitive). The only advantage to pointing it to #msg is so you can refer to is as "this" in the function call. I had assumed you had a UL object that was having LI items put inside it, but if you've copied this call from an example, you can quite easily make the event call as $("form").ajaxSuccess It doesn't need to point at the control it's going to change, it just needs to point as any control.
PS there are a couple of typo's.. read between my terrible typing :)
PPS See if this works: $("form").ajaxSuccess(function(evt, request, settings) { alert('ajax event'); });
PPPS and make sure you have a form element!
|