i wanna send keystrokes typed in a text field but only in 1s interval.
this is to reduce the load of sending an ajax request on each keypress.
so eg. if the user types 4 letters within a sec the request will send all these 4 letters. and lets say he types nonstop in 1 min, then the script will send on 1s interval till he stops typing.
at the moment my script looks like this:
$("#type_post").live('keyup', function() {
$.post('posts.php', {post: $("#type_post").val()});
});
but that sends on everything keypress.
could someone help me out here
UPDATE: here is the code i used.
var last_post = '';
$('#type_post').focus(function() {
// check if text has been changed every second when input field is focused
setInterval(function() {
if($('#type_post').val() != last_post)
{
// if changed, post it and set the new text as last text
$.post('posts.php', {post: $("#type_post").val()});
last_post = $("#type_post").val();
}
}, 1000);
});