I have implemented a little "live-search" on a site using jquerys ajax-function. Works most of the time perfectly. Sometimes the user types the search-word too fast and the results are mixed up. For example typing "google" results in a list containing all results with the word "googl", because the answer from "googl" came after the answer from "google".
$("#search").keyup(function () {
var search = $(this).val();
console.log(search);
$.ajax({
url: "index.php",
type: "GET",
data: {
s: search,
},
cache: false,
success: function(html, status, xhttp) {
$(".list").html(html);
console.log("result for "+search);
},
});
});
I can not use the parameter "async", because it is deprecated.
Are there any mechanisms to show the answers in the right sequence? Do I have to add some delay while typing the word?
Regards Jens