【问题标题】:Why isn't the jquery Autocomplete minlength property not working with ajax call为什么 jquery Autocomplete minlength 属性不能与 ajax 调用一起使用
【发布时间】:2015-02-02 13:49:09
【问题描述】:

我正在使用 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

当我在该文本字段上快速输入数据时,我得到了 Uncaught TypeError: undefined is not a function under browser console

问题 2

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

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

【问题讨论】:

    标签: jquery autocomplete


    【解决方案1】:

    您使用了错误的自动完成功能。您不必处理关键事件。自动完成插件为您完成。您必须告诉自动完成构造函数您的来源将是一个 ajax 调用。 看这个帖子里的答案How to use source: function()... and AJAX in JQuery UI autocomplete

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-17
      • 1970-01-01
      • 2019-07-24
      • 1970-01-01
      相关资源
      最近更新 更多