Last active
December 22, 2016 16:42
-
-
Save muratsu/3a0e19d777ec9e330ef4f0589aa6ba9b to your computer and use it in GitHub Desktop.
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
// 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