The error says you didn't provide suggestions array withing your JSON respone.
As you can see in the docs of jQuery-Autocomplete:
https://github.com/devbridge/jQuery-Autocomplete#response-format
the expected response format is:
{
// Query is not required as of version 1.2.5
query: "Unit",
suggestions: [
{ value: "United Arab Emirates", data: "AE" },
{ value: "United Kingdom", data: "UK" },
{ value: "United States", data: "US" }
]
}
... which in your case of JSON response route would mean more or less something like this:
Route::get('/admin/searches', function(){
$in = array(
"suggestions" => array(
array("value" => "one", "data" => "ON"),
array("value" => "two", "data" => "TW"),
array("value" => "three", "data" => "TH"),
array("value" => "four", "data" => "FO"),
)
);
return Response::json($in);
});
BTW: make sure your AJAX query really hits "/admin/searches" route.
Hello !
I've been turning around this for a while, so here is a little extra advise: don't forget to provide an empty suggestions array if you don't have any results for the query.
I know this post is old but I got really bad issue in autocomplete would you point out what am I missing.
I have just followed marekmurawski 1 year ago post.
$('.test').autocomplete({
serviceUrl: '/application/test',
dataType: 'json',
type: 'GET',
onSelect: function (suggestion) {
$('.test-msg).html('You selected: ' +suggestion.value+ '/'+suggestion.data.email);
},
onInvalidateSelection: function() {
$('.test-msg').html('You selected: none');
},
});
Issue below:
I completely type Adams Apple but why other suggestions text won't hide. It always there. Please help!
aaesis said:
I know this post is old but I got really bad issue in autocomplete would you point out what am I missing.
I have just followed marekmurawski 1 year ago post.
$('.test').autocomplete({ serviceUrl: '/application/test', dataType: 'json', type: 'GET', onSelect: function (suggestion) { $('.test-msg).html('You selected: ' +suggestion.value+ '/'+suggestion.data.email); }, onInvalidateSelection: function() { $('.test-msg').html('You selected: none'); }, });
Issue below:
I completely type Adams Apple but why other suggestions text won't hide. It always there. Please help!
I'm having the same issue. Did you ever figure out a fix for this?
to change tables name, just to meet the required array format, just do as i did before
$suggestions = User::select('name AS value', 'id AS data')->where('name', 'LIKE', '%'.Input::get('name').'%')->get();
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community