jquery autocomplete using json -
I have tried many things, but I could not understand this confusing illusion.
I have it
& lt; Input id = "wba" type = "search" name = "q" value = "" class = "search box" /> & Lt; Input type = "submit" value = "go" class = "search button" />
Also a php file
header ('cache-control: no-cache, required-recycling'); Header ('content-type: application / jason'); $ Arr = array ('test' = & gt; 'hello world'); Echo json_encode ($ arr);
For Javascript, I have tried everything from JPYar's website to demo, but no luck ... someone helped me to set up a complete data display Does it?
Edit
$ (function () {function log (message) {$ (" ) .prependTo ($ ("$ log"); $ ("scrolltop");} $ ("# wba"). Autocomplete ({source: function (request, response) {$. Ajax ({url: "search.php", data type: "jsonp", data: {featureClass: "P", style: "full", maximum illumination: 12, name_stars: request.term}, success: function (Data) {response ($ .max (datasheets, functions) {alert (item); window .console.debug (item); return {label: item.name, Note: item.url}})}}})}, select minnam: 2,: function (event, UI) {log (ui.item? ("Selected:" + ui.item .name): "selected None, the input was "+ this.value";}, open: work () {$ (this) .removeClass ("ui-corner-all"). AddClass ("ui-corner-top");} Do: function () {$ (this) .removeClass ("ui-corner-top"). AddClass ("ui-corner-all");}});});
This code is from the jqueryui website (demo) ...
This should be something like this
// js $ (function () {$ ("# wba"). Autocomplete ({source: function (request, response) {$. Ajax ({url: "search.php", data type: "jsonp", data: {q: request.term}, success: function (data) { Response ($ .max (data, function (value, key) {return {label: value.label, value: value.val}}))}}}}}}, minnamban: 2});}); // PHP $ result = array (array ('label' = & gt; '(' Label1 ',' val '=>' value1 '), array (' label '= & gt;' label2 ',' val '$' ("Value2"); // alternatively user input ($ _GET ["input_value", '' '& gt;' value2 '), array (' label '= & gt;' label3 ',' val '=> ], Do something with $ _GET ['callback'] echo. ('.json_encode ($ result).'); ''
I do not know why but it works ...
Comments
Post a Comment