I am working on a jQuery AutoSuggest plugin inspired by an Apple spotlight.
Here is the generic code:
$(document).ready(function() {
$('#q').bind('keyup', function() {
if( $(this).val().length == 0) {
$('#q-suggestions').fadeOut();
} else {
$("#q").css("background-image","url(/images/ajax-loader.gif)");
$.ajax({
url: '/search/spotlight/',
data: {"q": $(this).val()},
success: function(data) {
$('#q-suggestions').fadeIn();
$('#q-suggestions').html(data);
$("#q").css("background-image","url(/images/icon-search.gif)");
}
});
}
});
The problem that I want to solve well and elegantly does not kill the rank. At the moment, the code above gets to the server every time you enter the key, and did not wait for the text to complete. What is the best way to solve this problem? A. Kill the previous AJAX request? B. What type of caching is AJAX? C. Adding some type of delay to send .AJAX () when a person stopped typing in 300 ms or so?
source
share