This.source is not a function error when 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 was messing with, it says TypeError: this.source is not a function. Where am I wrong, correct me ???screenshot of Error and Json from response

+3


source to share


1 answer


jQuery Ajax methods are not blocking, so it looks like you are trying to set the autocomplete source before the previous method is restored. You probably want to move the assignment autocomplete

to the success method of your call .ajax()

.

So, instead of what you have, use:



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

      

+11


source







All Articles