Abort A Previous Ajax Request In jQuery

When using Ajax there will be changes ,where you will need to cancel the Ajax call. I found Aborting is useful while building a search as you type feature and I would abort the previous search and request a new Ajax search each time they typed a new letter. Since their old word has changed to a new word and therefore new meaning, completing the old request is having no purpose or reason since the new word is an entirely different meaning.

Luckily jQuery has made this almost easy as you can see by my example below.

Html

JQuery

Now you can type something for each keyup() event it will cancel the previous Ajax request and it will make new request to the sever.That is it, Simple and straightforward isn’t it.

Published
Categorized as JQuery

By Arjun

I am Arjun from Hyderabad (India). I have been working as a software engineer from the last 7+ years, and it is my passion to learn new things and implement them as a practice. Aside from work, I like gardening and spending time with pets.

0 0 vote
Article Rating
Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Andrew
Andrew
1 year ago

This does not work for some reason – better solution: https://stackoverflow.com/a/16751040/3273588