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

con*_*rsz 3 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");
      }
    });
  }
});
Run Code Online (Sandbox Code Playgroud)

Ror*_*san 7

autocomplete()jQueryUI库中的一个方法.你需要添加对它以及 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>
Run Code Online (Sandbox Code Playgroud)