Skip to content

Instantly share code, notes, and snippets.

@imzjy
Forked from bit4bit/pollurl.js
Created April 14, 2022 11:46
Show Gist options
  • Save imzjy/5f3ff1f08a9df7fe4a77b8390fecad8b to your computer and use it in GitHub Desktop.
Save imzjy/5f3ff1f08a9df7fe4a77b8390fecad8b to your computer and use it in GitHub Desktop.
polling jquery
function pollUrl(url, renderer) {
return function(render){
if(render == undefined) { render = renderer; }
$.getJSON(url, function(data){
render(data);
}).always(function(){
setTimeout(pollUrl(url, render), 5000);
});
};
}
/*now poll and render*/
pollUrl("localhost/stats")(function(data){
$("#view").html(data);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment