I just wanted to ask. I have text input to allow users to type their city.
jQuery has a keyup event linked to this input and sent an AJAX call after each character change.
I find however many unrequired AJAX calls are sent as the person is typing and depending on the number of results this can slow down performance here.
Is there a way to cancel AJAX calls if a new call is made? Is there a better way to do this?
An example can be seen here: http://www.datingjapan.co
You can use the
abortmethod of thejqXHRobject returned by theajaxmethod (other AJAX methods likegetandpostreturn ajqXHRinstance too):Note that the
jqXHRobject is effectively just an extension ofXMLHttpRequest, andXMLHttpRequestitself also has anabortmethod.