Alright so I've got this script sort of working. The ajax call works and the correct data is returned. The problem is that when keystrokes are pressed quickly (not real quickly, just normal typing speed), then the animations keep going back and forth, and every ajax call is still executed.
How can I make it so that:
1) the ajax calls don't stack up and 2) the fadein and fadeout animations don't keep stacking up
I have this javascript:
$(document).ready(function(){
$t = $("#data-users");
$('#data-overlay').css({
opacity : 0.5,
top : $t.offset().top,
width : $t.outerWidth(),
height : $t.outerHeight()
});
$('.loader').css({
top : ($t.height() / 2),
left : ($t.width() / 2)
});
$('.findit').keyup(function(){
var search;
search = $(this).val();
$('#data-overlay').fadeIn();
//get the data
$.post(
'/users/testajax',
{
search: search
},
function(responseText){
$("#data-users").html(responseText);
$('#data-overlay').fadeOut();
},
'html'
);
});
});