Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSON format for jQuery UI Autocomplete

The documentation for jQuery UI Autocomplete states that the source property can be set to a URL that returns the suggested items in JSON format. However, it doesn't elaborate further what the structure of this JSON result is supposed to look like. Could anyone post an example? Thanks!

like image 888
Tony the Pony Avatar asked Nov 16 '10 13:11

Tony the Pony


People also ask

How does Autocomplete work in jQuery?

In the process of searching a specific value, the jQuery UI autocomplete selection feature provides the user with some string suggestions for the input area which effectively saves time. The autocomplete select action is triggered when the user selects one of the options from the pre-populated list.

How can create Autocomplete search box in jQuery?

Syntax: $("TagId"). autocomplete({ source : itemList // List of Words. })

What is Request term?

(Entry 1 of 2) 1 : the act or an instance of asking for something. 2 : something asked for granted her request. 3 : the condition or fact of being requested available on request. 4 : the state of being sought after : demand.

How display image in jQuery ui Autocomplete textbox in PHP?

Here we will make autocomplete textbox, in which make list pre-populated search result with image. This feature we will make by add custom html tag in jQuery UI autocomplete method by add _renderItem. Here we will use __renderItem method, by using this method we will add custom HTML code in autocomplete textbox.


4 Answers

Moved the answer here from my comment:

[{"label":"mylabel","value":"myvalue"},...] 

I found it to be this format that .autocomplete is looking for for jquery UI 1.8

like image 125
James Avatar answered Oct 17 '22 12:10

James


This is a JSON Format

{source: ["Milan", "Turin", "Venice", "Florence", "Rome"] }

or another source

{source: ["c++", "java", "php", "coldfusion", "javascript", "asp", "ruby"]}
like image 44
DavideDM Avatar answered Oct 17 '22 11:10

DavideDM


using firebug we can see this format for json

[{"id":"Podiceps nigricollis","label":"Black-necked Grebe","value":"Black-necked Grebe"}]

I used json_encode

$a[$x] = array("id" => $row["id"],"label"=>$row["label"],"value"=>$row["value"]);
}
//echo JSON to page
    $response =  json_encode($a);
echo $response;
like image 2
phonck Avatar answered Oct 17 '22 13:10

phonck


I do a call to a Java Spring controller that simply returns the information below (in JSOn format). I build it with JSTL. But I don't know what kind of backend you use. But in Allmost every language you can simple output some JSON.

Example:

{
  "results": [{
      "id": " Canned",
      "name": " Canned"
    }, {
      "id": 64,
      "name": "Added Sulphites"
    },
    {
      "id": 3,
      "name": "age"
    }, {
      "id": "age",
      "name": "age"
    }, {
      "id": 59,
      "name": "age group"
    },
    {
      "id": "Allergen",
      "name": "Allergen"
    }, {
      "id": 85,
      "name": "Anchovies"
    }
  ]
}

I dislike autocomplete. maybe you found a better solution in flexbox: http://flexbox.codeplex.com/

like image 2
Michel Avatar answered Oct 17 '22 11:10

Michel