对象不支持属性或方法'autocomplete'

时间:2013-11-12 12:10:35

标签: jquery

添加一些自动完成代码后,我收到此错误消息。我确信它在网上搜索后与重复的jQuery引用有关,但我只引用了一次。

应用程序使用母版页,但有问题的页面没有使用它,所以我在两者中都引用了jquery。

$(".autosuggest").autocomplete({
  source: function(request, response) {
    $.ajax({
      type: "POST",
      contentType: "application/json; charset=utf-8",
      url: "CustomerTypes.aspx/GetAutoCompleteData",
      data: "{'Customer':'" + document.getElementById('txtCustomerType').value + "'}",
      dataType: "json",
      success: function(data) {
        response(data.d);
      },
      error: function(result) {
        alert("Error");
      }
    });
  }
});

2 个答案:

答案 0 :(得分:7)

autocomplete()jQueryUI library中的一种方法。您需要添加对的引用以及作为jQuery.js:

<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.0/themes/smoothness/jquery-ui.css" />
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.min.js"></script>

答案 1 :(得分:4)

你必须在jquery之后添加这个库:

<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
相关问题