JSON for Jquery autocomplete -
i've json response php file.
[{"name":"kiev"},{"name":"kiev metro"},{"name":"kiev-dnepro"},{"name":"kiev-dnepro"},{"name":"kiev-donetsk"},{"name":"kiev-donetsk"}
how can use standard jquery autocomplete? autocomplete function request seems cant parse response json (simple array works fine). me please
derin, yes that's it. works fine! want modify little. getting more data in response , i'd display near of main autocomplete input
var infogisname = null; var infogistype = null; var infogislocationid = null; var infogisparentid = null; $('#gisname').autocomplete({ source: function(request, response) { $.getjson("autocomplete.php", { term: request.term }, function(result) { response($.map(result, function(item) { infogisname = item.name; infogistype = item.gis_type; infogislocationid = item.location_id; infogisparentid = item.parent_id; return item.name; })); }); }, change: function(event, ui) { $('#infogisname').html(infogisname); $('#infogistype').html(infogistype); $('#infogislocationid').html(infogislocationid); $('#infogisparentid').html(infogisparentid); }, minlength:3 }); });
so how change data in fields when changed text in autocomplete input? see last values json recordset
you use formatitem
option:
$('#foo').autocomplete({ url : '/foo', formatitem: function(item, position, length) { return item.name; } });
for jquery ui autocomplete here's how achieve this:
$('#foo').autocomplete({ source: function(request, response) { $.getjson('/foo.php', { q: request.term }, function(result) { response($.map(result, function(item) { return item.name; })); }); } });
Comments
Post a Comment