I am currently using a keyup function to initiate my autosave.php file which auto saves information to a table. However, I am starting to find that the keyup seems to be inefficient due to fast typing and submitting long strings.
How can I have the ajax submit every x seconds, instead of each keyup after so many ms?
$(document).ready(function() { // Handle Auto Save $('.autosaveEdit').keyup(function() { delay(function() { $.ajax({ type: "post", url: "autosave.php", data: $('#ajaxForm').serialize(), success: function(data) { console.log('success!'); } }); }, 500 ); }); }); var delay = (function() { var timer = 0; return function(callback, ms) { clearTimeout (timer); timer = setTimeout(callback, ms); }; })();