API call previous ajax request cancel by below code, Search by ajax then code useful for improve search functionality.
Demo URL: http://weanswer.xyz/demo/CancelPreviousRequestofAjaxCall/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
<!DOCTYPE html> <html> <head> <title>Api calling</title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> </head> <body> <h2>Demo- right click->inspect->Network</h2> </body> <script type="text/javascript"> var currentRequest=null; function apiCall(){ if(currentRequest != null) { currentRequest.abort(); } currentRequest = jQuery.ajax({ type: "GET", url: "https://httpbin.org/get", data: "name=AbC", success: function(data){ console.log( "Data Saved: " + data ); } }); } apiCall(); apiCall(); apiCall(); apiCall(); apiCall(); apiCall(); apiCall(); apiCall(); </script> </html> |
More Stories
Convert Unix Time to other Time Zone in Java script
Clone (Copy) with selected value using jQuery
html5 capture image from camera