eg. In the search form, when the user enters some text, at this time the AJAX request should send a keyup for each keyup event with the search key in the form of a query string. The search key will be the value from the input field.
If the user enters "ABCD", in this case 3 AJAX requests must first be killed / canceled, because in the fourth AJAX search request there will be "ABCD"
$(document).ready(function(){ $("#searchInput").keyup(function(){ ajaxSearch( $("#searchInput").val() ); }); });
In the keyup event, I call the following function "ajaxSearch ()".
function ajaxSearch(searchKey) { $.ajax({ type: "get", url: "http://example.com/ajaxRequestHandler/", data: "action=search&searchkey=" + searchKey }).done(function() { }); }
source share