外出焦点可以停止通话吗?

时间:2010-09-13 16:00:54

标签: jquery ajax

好的,所以我有一个自动填充字段heere,它会在每次按键时发出ajax请求...但是.focusout()应该会终止自动完成,因为直观地说,如果用户离开该字段并移动到下一个字段你不应该给你任何建议,因为你已经离开了这个领域。关于如何做到这一点的任何想法。这是我的代码。我正在使用此自动填充plugin,这是我的代码凭据。输入艺术家并离开该字段以查看我的意思

电子邮件:test@test.com传递:test12

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

1 个答案:

答案 0 :(得分:1)

尝试使用 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();

});

取自 previous SO answer 。只有在.autoComplete()使用XMLHttpRequest实例进行通话时,上述操作才有效。