I'm polling my database every one second and I need it to do something only after a new entry has been submitted to the database; it can't just re-pull everything. Any help?
You can periodically check if the latest record ID matches the last ID pulled by your script, and if not, pull the new data. Example:
function updateView(id) {
$.get("foo.php", { lastId: id }, function(response) {
if(response != lastId) {
// new entry in DB, do something special
// and set lastId to the newly fetched ID
lastId = id;
}
});
}
var i = setInterval(function() { updateView(id) }, 10000);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With