Possible Duplicate:
Jquery POST for suggestion list
I have the next code and it works well, the problem is that when the user finishes writing the word, the script keeps creating post calls and changing the suggestion list constantly.
I want to do something that if the user keeps writing a word, the script stops all the post calls to only do the last.
$("#inputString").keydown(function() {
lookup($(this).val());
//alert('a');
});
function lookup(inputString) {
if(inputString.length == 0) {
$('#suggestions').fadeOut(); // Hide the suggestions box
} else {
$.post("../jsonshow.php", {q: ""+inputString+""}, function(data) { // Do an AJAX call
$('#suggestions').fadeIn(); // Show the suggestions box
$('#suggestions').html(data); // Fill the suggestions box
});
}
}
You can use
$.ajaxinstead of$.postand abort theprevious requestsand send only thecurrent Request..Something of this sort..