Created
July 22, 2011 12:47
-
-
Save dbellettini/1099383 to your computer and use it in GitHub Desktop.
Javascript jQuery JSON polling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Poller (url, callback) { | |
this.url = url; | |
this.callback = callback; | |
this.start = function(interval) { | |
var url = this.url; | |
var callback = this.callback; | |
var fn = function() { | |
jQuery.getJSON(url, callback); | |
}; | |
fn(); | |
this.interval = self.setInterval(fn, interval); | |
}; | |
this.stop = function() { | |
if (this.interval) { | |
self.clearInterval(this.interval); | |
} | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment