views:

114

answers:

1

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>");
});
+2  A: 

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.

Evildonald
what does that "#msg" thing do in first line? I don't have to replace it with something?
HelloMoon
#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").ajaxSuccessIt doesn't need to point at the control it's going to change, it just needs to point as any control.
Evildonald
PS there are a couple of typo's.. read between my terrible typing :)
Evildonald
PPS See if this works: $("form").ajaxSuccess(function(evt, request, settings) { alert('ajax event'); });
Evildonald
PPPS and make sure you have a form element!
Evildonald
What if i want to load a function after any ajax call that is done, which is way past after the page has loaded...based on a user choice.
crosenblum
@crosenblum - see the PPS example.. it doesn't trigger when the form is loaded.. it triggers after ANY jQuery ajax request. The "form" is merely the control it anchors the javascript against.
Evildonald