tags:

views:

37

answers:

1

Ok so I have an autocomplete field heere that is making an ajax request every keystroke...But the .focusout() should kill the autocomplete because intuitively if the user leaves the field and moves on the next field it should not give you any suggestions bacause you already left the field. Any ideas on how to do this. Here is my code. I am using this autocomplete plugin and here is my code the credentials. Enter an artist and leave the field to see what i mean

email: [email protected] pass: test12

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

Try to use abort():

var theCall = $('#request_artist').autocomplete({
                  serviceUrl: '<%= ajax_path("artistName") %>',
                  minChars:1,
                  width: 300,
                  delimiter: /(,|;)\s*/,
                  deferRequestBy: 0, //miliseconds
                  params: { artists: 'Yes' },
                 });
// ...
// When you decide you want to cancel the call
$('#request_artist').blur(function() { 

    theCall.abort();

});

Taken from this previous SO answer. The above will only work if, .autoComplete() uses an XMLHttpRequest instance to make the call.

Peter Ajtai