jquery ui autocomplete database
- by user343925
Hello,
I'd like to use jQuery UI autocomplete in order to load a list from my database but I don't know wich method I should use to do so.
I tried to use the "Remote datasource" method [url]http://jqueryui.com/demos/autocomplete/#remote[/url], but it obviously doesn't work.
I have the following code :
js:
$(function() {
$("#client").autocomplete({
source: "nom.php",
minLength: 2,
select: function(event, ui) {
alert(ui);
}
});
});
html :
<label for="client">Client</label>
<input name="client" id="client" class="ui-autocomplete ui-widget-content ui-corner-all" />
php:
$query = "SELECT nom from personne";
$result = mysql_query($query, $db);
while($row = mysql_fetch_assoc($result)) {
foreach($row as $val)
$tab[] = $val;
}
print json_encode($tab);
It does work with ["hello","test1","test2"] instead of the url but I need to load datas form database so pls tell me how I should do.
thank you