简体   繁体   English

实现自动完成时出现“this.source 不是函数”错误

[英]“this.source is not a function” error while implementing autocomplete

$(document).ready(function(){
   var var_name=null;
   $('#id1').click(function(){

      $.ajax({
         type:"GET",
         url:" ggs.erm.servlet.setup5.Page",
         success:function(response){
            var_name=response;
            console.log(response);
         }
      })
   });
   $("#id").autocomplete({source:var_name});
});


This is the Code I am messing with,It says TypeError:this.source is not a function.这是我弄乱的代码,它说 TypeError:this.source 不是函数。 Where I am wrong,Correct me???我哪里错了,纠正我???响应中错误和 Json 的屏幕截图

jQuery Ajax methods are non-blocking, so it looks like you're trying to set an auto-complete source before the previous method resolves. jQuery Ajax 方法是非阻塞的,因此看起来您正在尝试在前一个方法解析之前设置自动完成源。 You probably want to move the autocomplete assignment into the success method of your .ajax() call.您可能希望将autocomplete分配移动到.ajax()调用的成功方法中。

So, instead of what you have, use:所以,而不是你所拥有的,使用:

$.ajax({
    type:       "GET",
    url:        "ggs.erm.servlet.setup5.Page",
    success:    function(response) {
        $("#id").autocomplete({ source: response });
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM