such a problem. I am writing a smart search on the site, when I click on the button I send a request for a sample of the database.
For example, I enter the word "table", the request leaves for the word "hundred", then I enter the letter "l" and the request leaves with the word "table".
Then the request with the word "table" comes faster, and after it comes the answer of the request "one hundred" and, accordingly, overrides the answer I need. Is there any way out?
here is the code
$(document).on('keyup', '#fastcat', function () { var ad = $(this); $.ajax({ type: "GET", url: "/ajax/fastcat?q=" + ad.val(), beforeSend: function () { if (ad.val().length > 1) { $(".fastcat_auto").removeClass('visible'); $('.fastcat_div .loader').show(); } }, success: function (html) { $('.fastcat_div .loader').hide(); if (html != 'fail') { $('.fastcat_auto').html(''); $('.fastcat_auto').html(html); $(".fastcat_auto").addClass('visible'); } else { if (ad.val().length > 1) { $('.fastcat_auto').html('<ul><li>Ничего не найдено.</li> </ul>'); $(".fastcat_auto").addClass('visible'); } } } }); });