Delayed AJAX update

Doing a lot of small AJAX based updates is rather expensive. To solve this my idea was that an AJAX update should be made when the user is finished doing changes (that way you don't make an AJAX update for every change, but only one when the user is finished doing changes).

Here is some pseudo code that delays the AJAX update 10 seconds every time an user edits something:

var Timeouts = {};

function ajaxUpdate() {
   alert('We AJAX update in here!');
}

function updateItem(item_id) {
   ...
   var timeout = Timeouts[item_id];
   if(timeout)
      clearTimeout(timeout);
   Timeouts[item_id] = setTimeout(ajaxUpdate, 10000);
}
AJAX and comet · Code · Code improvement · JavaScript · Tips 11. Sep 2007
5 comments so far

Is 10 second may be too long? a user could leave the page before that timeout? Or there could be a browser, or system crash....

Braydon:
It depends on how critical the update is and what kind of website it is.

I use this technique for an upcoming Todoist feature and I know that people have Todoist open for longer than 10 seconds.

I see, it's too bad it's too expensive. How does the Ajax update work? Do you use a form to send the information?

Why's it expensive? It's less expensive than an update for every change event on a text field or something. To be honest, this technique's a bit old for me, but I guess if you haven't thought about it before it's rather useful.

Good!Can some one tell me where i can find all information about compyuters.I wana learn about compyuters.

Post a comment
Commenting on this post has expired.
© 2000-2009 amix. Powered by Skeletonz.