【问题标题】:jQuery autocomplete getting the errorjQuery自动完成得到错误
【发布时间】:2016-09-29 03:19:13
【问题描述】:

我正在尝试实现 jQuery 自动补全。 我在我的项目中导入 jQuery 文件并在我的 JSP 中使用它们:

 <script src="JQUERY/development-bundle/jquery-1.8.3.js"></script>
        <script src="JQUERY/development-bundle/ui/jquery.ui.core.js"></script>
        <script src="JQUERY/development-bundle/ui/jquery.ui.widget.js"></script>
        <script src="JQUERY/development-bundle/ui/jquery.ui.position.js"></script>
        <script src="JQUERY/development-bundle/ui/jquery.ui.menu.js"></script>
        <script src="JQUERY/development-bundle/ui/jquery.ui.autocomplete.js"></script>
        <script type="text/javascript" src="js/employeeAutocomplete.js"></script>

这里我在JSP文件中写了一个输入框,通过JSP调用JS文件:

<input type="text" id="empauto" class="searchbox">  

这里我调用了一个JS文件:

$(document).ready(function(){       

 $('#empauto').autocomplete({
          source: function(request,response ){
                $.ajax({
                    url: "empauto.do?method=getAutoEmpdetails",
                    //dataType: "json",
                    data: {
                        featureClass: "P",
                        style: "full",
                        maxRows: 12,
                        name_startsWith: request.term
                    },
                    success: function(data) {
    //                  alert(data.list1[0].empname);
                        response( $.map( data.list1, function( item ) {
                            return {
                                label: item.empname,
                                value: item.empname,
                                id : item.email+"("+item.phone+"("+item.shiftname+"("+item.deptname+"("+item.emplocation+"("+item.empid
                            }
                        }));
                    }

                });
            },

      });


    });

当我调用自动完成方法时,我收到以下错误:

  Uncaught TypeError: Object [object Object] has no method 'autocomplete'   

这个错误会出现在source:function(request,response)之前

【问题讨论】:

  • 试试dataType: "jsonp"
  • $.ajax 内设置 dataType: "json"
  • @Pranav c,@Tomanow 我尝试了两种方法都不起作用
  • 确保 jQuery 和 jQuery-UI 正确加载
  • 一切都正确加载

标签: javascript jquery autocomplete


【解决方案1】:

你可以参考一下吗:Uncaught TypeError: Object [object Object] has no method 'autocomplete'

当我们有多个版本的 jQuery 时,通常会发生这种情况。

注意:由于 cmets 添加需要超过 50 个点,因此无法将其添加到 cmets 中

【讨论】:

  • 你的建议很好,但这里只导入一个版本,见上面的代码。如果你知道,请给我另一个解决方案
猜你喜欢
  • 2013-09-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-01-18
  • 2011-04-02
  • 2011-02-03
  • 2016-12-27
  • 2017-05-09
相关资源
最近更新 更多