Support the ongoing development of Laravel.io →
Requests Views Forms
Last updated 2 years ago.
0

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.

Last updated 2 years ago.
0

Thank you that worked!!

Last updated 2 years ago.
0

it worked for me. thank you so much.

Last updated 2 years ago.
0

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.

Last updated 9 years ago.
0

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:

Issue Screenshot

I completely type Adams Apple but why other suggestions text won't hide. It always there. Please help!

Last updated 9 years ago.
0

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:

Issue Screenshot

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?

0

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();
0

Sign in to participate in this thread!

Eventy

Your banner here too?

louposk louposk Joined 8 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.