jquery autocomplete with remote json object -
i want make input field have jquery autocomplete fetch company names database , display user. below snippet found on jquery.com. want rewrite fit needs , need help.
$(function() { function log( message ) { $( "<div/>" ).text( message ).prependto( "#log" ); $( "#log" ).attr( "scrolltop", 0 ); } $( "#company_name" ).autocomplete({ source: function( request, response ) { $.ajax({ url: "inc/company_name.php", datatype: "jsonp", data: { featureclass: "p", style: "full", maxrows: 12, name_startswith: request.term }, success: function( data ) { response( $.map( data.geonames, function( item ) { return { label: item.name, value: item.name } })); } }); }, minlength: 2, select: function( event, ui ) { log( ui.item ? "selected: " + ui.item.label : "nothing selected, input " + this.value); }, open: function() { $( ).removeclass( "ui-corner-all" ).addclass( "ui-corner-top" ); }, close: function() { $( ).removeclass( "ui-corner-top" ).addclass( "ui-corner-all" ); } }); });
in source attribute, upon sucess, want replace
response( $.map( data.geonames, function( item ) { ... }
with proper code display json object data. below json object created in php.
<?php $arr = array ( 'item' => 'company name' ); echo json_encode($arr); ?>
try autocomplete plugin:
http://docs.jquery.com/plugins/autocomplete
the example:
var data = "core selectors attributes traversing manipulation css events effects ajax utilities".split(" "); $("#example").autocomplete(data);
you modify fit yours using ajaxloader arte:
http://plugins.jquery.com/node/12682
you use code:
/* init arte engine */ $.arte({'ajax_url':'remote_xml_file_url'}).add_action("xml_node", fct); /* function called every tick new node */ function fct(data){ window.data = data; }
Comments
Post a Comment