3
$(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. Where I am wrong,Correct me???screenshot of Error and Json from response

1
  • var var_name=null; instead declare var var_name=[ ]; Commented Jan 30, 2013 at 7:37

1 Answer 1

11

jQuery Ajax methods are non-blocking, so it looks like you're trying to set an auto-complete source before the previous method resolves. You probably want to move the autocomplete assignment into the success method of your .ajax() call.

So, instead of what you have, use:

$.ajax({
    type:       "GET",
    url:        "ggs.erm.servlet.setup5.Page",
    success:    function(response) {
        $("#id").autocomplete({ source: response });
    }
});
Sign up to request clarification or add additional context in comments.

1 Comment

After indenting the code correctly you can even see that he put the assignment of var_name to the source property even outside of the click handler.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.