views:

202

answers:

0

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 http://jqueryui.com/demos/autocomplete/#remote, 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 show all the values no matter what I enter, but when I copy the result of nom.php and past it next to source: it does work...

thank you for your helm