Home > database >  Make sure only last AJAX result applied
Make sure only last AJAX result applied

Time:02-27

I use AJAX call for filtering the records. So the the AJAX request is called everytime we click checkbox. When the checkboxes get clicked rapidly, sometimes the result isn't correct since the result applied isn't the last one (async). How can I make sure only the last AJAX result is applied without affecting the performance?

CodePudding user response:

You can send in every request a variable we call "echo". The echo variable will be declared before request and will be incremented at every request. The API will send back the echo variable it has received. You'll only handle the request which returned the echo value which matches your current echo variable value. You can disable all buttons until request is done too!

  • Related