0

We have a search bar and pagination on the page, using jquery to make ajax request As one start searching for particular record many ajax request is being fired , though we added ajax abort to the previous request but in rails query is still happening for all,

How to stop the rails processing when previous ajax request is aborted

1 Answer 1

3

If the Rails server has received the AJAX request, .abort will not stop the server from executing it. This stackoverflow answer describes how you could use readyState to check if the last request was completed or not.

However, I believe what you're looking for is a debounce function. A debounce function limits the rate at which a function gets fired. You could use that to make sure that the search bar fires a backend request only after certain seconds have passed since it last received an input. That would greatly reduce the number of queries that get sent to the Rails server.

Sign up to request clarification or add additional context in comments.

1 Comment

You could also use a promise to ensure that the call is not repeated until the server responds.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.