PDA

View Full Version : How to make ajax call for every 5 seconds?



renganathan
25 Feb 2013, 6:16 AM
Hi All,

I want to make ajax call for every 5 seconds.

Can you guys suggest me how to do that ?

wojteks27
25 Feb 2013, 6:29 AM
Use this :


//we store setInterval's return value in case we want to clear the interval later on with clearInterval(myInterval)
var myInterval = setInterval(function() {
//here you put your AJAX request
}, 5000//5 seconds in ms);


PS.
of course if it is what you were looking for and I understood you correctly:)

Johnny Major
25 Feb 2013, 6:36 AM
You could use Ext.util.DelayedTask

Example



this.pollTask = new Ext.util.DelayedTask(function(){
Ext.Ajax.request({
url: pollUrl,
scope: this,
success: function(r) {
},
failure: function() {
}
});
this.pollTask.delay(5000);
}, this);


this.pollTask.delay(5000);

wojteks27
25 Feb 2013, 6:52 AM
According to Sencha docs here : http://docs.sencha.com/core/manual/content/timers.html, the correct way would be to use Ext.TaskManager.

Still I wonder why is it advised to use this solution instead of basic setInterval.
Can anyone explain?

renganathan
25 Feb 2013, 9:07 PM
Thanks All for your solution