Skip to content

Instantly share code, notes, and snippets.

@muratsu
Last active December 22, 2016 16:42
Show Gist options
  • Save muratsu/3a0e19d777ec9e330ef4f0589aa6ba9b to your computer and use it in GitHub Desktop.
Save muratsu/3a0e19d777ec9e330ef4f0589aa6ba9b to your computer and use it in GitHub Desktop.
// Make the ajax request
$.ajax({
url: '/demo',
method: "POST",
cache: false,
data: {
/*some data*/
}
})
.done(function(guid) {
pollRun.call(null, guid);
})
.fail(function(jqXHR, textStatus) {
console.log("Request failed: " + textStatus );
});
function pollRun(guid){
setTimeout(function(){
$.ajax({
url: '/foo',
data: {
/*some data*/
},
method: 'POST',
cache: false,
dataType: 'json'
})
.done(function(response) {
// If server is still working poll again
if (response.status === "working") {
pollRun(guid);
return;
}
/*biz logic*/
})
.fail(function(jqXHR, textStatus) {
console.log( "Request failed: " + textStatus );
});
}, 1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment