I have the following functions that is called every 2 seconds to load some data. It registers the funcion [do] to do the stuff with the response. (the example is simplified).
function doRequest (){
$.ajax({ url: 'www.google.com.pe', success: function (response) {do(response)} });
}
function do (text){
var i = setInterval(doRequest, 2000);
}
I wonder if there is any way that I can create a function that is called every time the [do] function is called with out needing to add a call to the listener inside the do function. Thank's in advance. If there is any better way to do it with jquery, like a plugin I'd appreciate the help.
[Edit] The idea is not whether it works or not. My question was about if I can add a custom listener to the "do" function wich was allready implemented. Something like addActionListener("do", "after", doSomeThingElse) So I could do some thing else just after the do function has finished.
2000
= 2 secs not 2 minutes. What you have in setInterval is milli seconds.. This is just a commentdo
.do
is a reserved word in Javascript.setInterval
's arguments need to be flipped - the function comes first, then the milliseconds: developer.mozilla.org/en-US/docs/DOM/window.setInterval