I am a bit bewildered. I have a function that calls an ajax search on keyup below.
$(document).on('keyup', '#search', function(e) {
$("#showPending").html("");
if ($('#showPending').is(':empty')){
if ( this.value.length > 2 ) {
var search = $("#search").val();
loadsearch(search);
}
}
});
Everything works great except if the user types a search parameter quickly he/she will get duplicate records appended to the #showPending table. If they type slowly they will get perfect results. I was under the impression the loadsearch function will not be called until after the #showpending element is empty because it is a synchronous function. Any ideas what I am doing wrong? Cheers! update: load search function (minimized) below:
function loadsearch(search){
$("#showPending").html("");
$.ajax({
url: "server-calls/load-search.php?callback=?",
type: "GET",
data: {search: search},
dataType: "jsonp",
crossDomain: true,
success: function (data, status) {
for(var i = 0; i < data.length; i++) {
var obj = data[i];
$("#showPending").append('<a href="javascript:void(0);">SEARCH RESULTS </a>');
}
}
});
}
loadsearch?#showPendingright before checking if empty. i.e. it will always be empty. I am not sure this resolves all your issues, but it is definitely not something you want to do.