Skip to content

Instantly share code, notes, and snippets.

@denzuko
Last active December 19, 2015 17:29
Show Gist options
  • Select an option

  • Save denzuko/5991975 to your computer and use it in GitHub Desktop.

Select an option

Save denzuko/5991975 to your computer and use it in GitHub Desktop.
Post #form to a restful api
var isPulse=true;
function heartbeat(){
if(isPulse){
var hb = setTimeout(heartbeat, seconds*1000);
//process stuff here
//isPulse can be whatever you want.
//It just needs to be something that will stop the recursive loop--an error condition, perhaps.
//Having a condition to stop this is a good idea, otherwise it will start acting like a memory leak.
//You could change the condition to be an amount of time, number of loops, or some other condition.
$('form').change(function()
{
console.log('success!');
$.ajax({
type: 'post',
url: 'process.php',
data: $(this).serialize(),
success: function() {
}
});
return false;
});
}
}
//function call is here
var hb = setTimeout(heartbeat, seconds*1000); //beat every 5 minutes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment