Reputation: 1037
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?
Upvotes: 4
Views: 3637
Reputation: 342775
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);
Upvotes: 13