Skip to content

Instantly share code, notes, and snippets.

@aindong
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aindong/37d9f7537546ca7bb654 to your computer and use it in GitHub Desktop.
Save aindong/37d9f7537546ca7bb654 to your computer and use it in GitHub Desktop.
Recursive ajax request (polling)
var checkForNewReading = function () {
$.ajax({
url: location.href + '/request',
type: 'GEt',
dataType: 'json',
success: function(data) {
if (data) {
// DO SOMETHING
}
checkForNewReading();
},
error: function(xhr, ajaxOptions, thrownError) {
console.log(thrownError);
}
});
};
checkForNewReading();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment