1

I am accessing a json API and making an ajax call to get the json, I am successful in doing that but I want to populate the names from the json as suggested text under the textbox. I am having issues doing that. Can any one suggest some thing please?

$("#state").autocomplete({
    source: function( request, response ) {
        var result = $.ajax({
            url: 'http://localhost:8181/jquery/api/states/regex?stateName='+request.term,
            method: 'GET',
            dataType: 'json',
            success: function(data) {
                //alert(data);
                response($.map(data, function(item) {
                    //alert(item.stateName);
                    return {
                        label: item.stateName,
                        value: item.stateName
                    };
                }));
            }
        });
        return result.responseText;
    },
    minLength: 1
})
}); 

I got it working Thanks!!

Tushar Gupta - curioustushar
  • 58,085
  • 24
  • 103
  • 107
Biggy_java2
  • 1,931
  • 3
  • 20
  • 21
  • possible duplicate of [How to return the response from an AJAX call from a function?](http://stackoverflow.com/questions/14220321/how-to-return-the-response-from-an-ajax-call-from-a-function) – Musa Jan 11 '13 at 19:03
  • What exactly is the issue you are having? Apart from the `return result.responseText;`, it looks fine to me. You are calling `response` and pass the items to it, just as you should. Please clarify your problem and create a http://jsfiddle.net/ demo if possible. – Felix Kling Jan 11 '13 at 20:50
  • I was able to fix the issue. I updated my initial post. Thanks! – Biggy_java2 Jan 17 '13 at 19:04

0 Answers0