2

Possible Duplicate:
How to cancel a jquery.load()?

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: test@test.com 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

Community
  • 1
  • 1
Matt Elhotiby
  • 43,028
  • 85
  • 218
  • 321

1 Answers1

3

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
  • 49,435
  • 16
  • 136
  • 136