mjgirl
mjgirl

Reputation: 1234

Autocomplete with external source

I found this example where autocomplete suggestions come from external source, here it is search.php:

http://jqueryui.com/demos/autocomplete/#multiple-remote

However I don't see there how the search.php is formatted, so I get no help of getting external source to work right. I would like to get my suggestions from database and html page. Help the newbie!

Upvotes: 0

Views: 3369

Answers (3)

sgmcb
sgmcb

Reputation: 11

The full code of the search.php file they use is also on github, here:

https://github.com/jquery/jquery-ui/blob/master/demos/autocomplete/search.php

Upvotes: 1

Michiel Cornille
Michiel Cornille

Reputation: 2097

Just look for a way to serialize objects into JSon on your platform, which should return something like this:

  [
    {
        "id": "Dromas ardeola",
        "label": "Crab-Plover",
        "value": "Crab-Plover" 
    },
    {
        "id": "Larus sabini",
        "label": "Sabine`s Gull",
        "value": "Sabine`s Gull" 
    },
    {
        "id": "Vanellus gregarius",
        "label": "Sociable Lapwing",
        "value": "Sociable Lapwing" 
    },
    {
        "id": "Oenanthe isabellina",
        "label": "Isabelline Wheatear",
        "value": "Isabelline Wheatear" 
    } 
]

Upvotes: 0

Gevious
Gevious

Reputation: 3252

The search.php return the data in the following format:

$result = array(
    'query'=>$this->params['url']['query'],
    'suggestions'=>$values,
    'data'=>$keys,
);

query is the search query the user entered (the results are cached in hidden divs on the page) suggestions are your results which will be displayed data is an optional parameter which contains an array of keys matching the suggested values

Upvotes: 1

Related Questions