开发者

Can the out focus stop the call?

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 autoc开发者_如何学Complete plugin and here is my code the credentials. Enter an artist and leave the field to see what i mean

email: test@test.com pass: test12

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜