views:

88

answers:

2

Ok so I have an autocomplete field that is making an ajax request every keystroke....which can slow things down alot. If you visit here and use the

email: [email protected] pass: test12

If you have firebug open and start typing fast you will see all the see all the ajax requests. My question is can i cancel the previous request if there is a more recent one. here is my code.

This is my autocomplete call using this plugin

$('#request_artist').autocomplete({
  serviceUrl: '<%= ajax_path("artistName") %>',
  minChars:1,
  width: 300,
  delimiter: /(,|;)\s*/,
  deferRequestBy: 0, //miliseconds
  params: { artists: 'Yes' },
});

From there I call the ajax from my rails application using

from my rails action I make a call to the itunes api

http://ax.itunes.apple.com/WebObjects/MZStoreServices.woa/wa/wsSearch?term=metalicca

really my question is, Is there a way to tell if an ajax is running and kill it

+3  A: 

You can try using the AJAX Queue/Cache/Abort/Block Manager, it was what I used when I had a similar problem. Using the abortOld option, the plugin will abort old requests when responses to newer requests come in.

Yi Jiang
+1  A: 

See a similar question: http://stackoverflow.com/questions/2813168

fullware