为什么 jquery 自动完成最小长度 属性 不适用于 ajax 调用

Why isn't the jquery Autocomplete minlength property not working with ajax call

我正在使用 Jquery UI Ajax 自动完成文本字段。

这是我的代码

http://jsfiddle.net/41w8b23q/1/

<input type="text" name="state" id="state" placeholder="state" required="" onkeypress="return nospecialCharacters(event)" class="ui-autocomplete-input error" autocomplete="off">

$("#state").on("keydown", function(event) {
    var statevalue = $("#state").val();
    if (statevalue) {
      $.ajax({
        type: 'GET',
        url: url + '/HHH/JUI/chdautosuggestatemodified?state=' + statevalue,
        jsonpCallback: 'jsonCallback',
        cache: true,
        dataType: 'jsonp',
        jsonp: false,
        success: function(respons) {
          $("#state").autocomplete({
             noResults : '',
            source: respons,
            minLength: 1
          });
        },
        error: function(e) {}
      });
    } else {
      //prevents();
      event.stopPropagation();
      //      event.preventDefault();
      event.stopImmediatePropagation();
    }
  });

现在我面临两个问题。

第 1 期

当我在该文本字段中非常快速地输入数据时,我得到 未捕获的类型错误:undefined 不是浏览器控制台下的函数

第 2 期

我面临的另一个问题是,即使我将最小长度提到为 1,它也不会显示数据,直到我输入 3 个字符??

问题 1 不是那么重要,但问题 2 是我需要解决的,您能告诉我如何解决吗??

您使用的自动完成功能有误。您不必处理关键事件。自动完成插件会为您完成。您必须告诉自动完成构造器您的来源将是一个 ajax 调用。 查看此线程中的答案 How to use source: function()... and AJAX in JQuery UI autocomplete