jQuery autocomplete error with JSON data
I'm getting a JSON array from server :
mysql_select_db('******') or die("Error connecting to db.");
$res = mysql_query("SELECT DISTIN开发者_C百科CT(valeur) as val FROM *****") or die(mysql_error());
while($r = mysql_fetch_assoc($res)){
$tab[] = $r['val'];
} echo json_encode($tab);
unset($tab);
And :
$.getJSON("autocomp.php?id=valeur", function(data){
$("#other-valeur").autocomplete({delay: 100, source: data, dataType: 'json'});
});
The server returns me a correct json array :
["UMTS","RAN","Swap","Regions","Brasseur",...]
But when i start typing something in the input, i get this message in firebug:
c is null
In the jquery code...
What i dont understand is that i'm doing the exact same thing for another input on the same page, and it work perfectly, the json array look the same, the code is the same...
It will not work because autocomplete need the property "id" and "value" in your json. this is not the case here.
Try to return the json like that :
[{"id":"1","value":"UMTS","comment":"umts comment"},
{"id":"2","value":"RAN","comment":"ran comment"},
{"id":"3","value":"Swap","comment":"swap comment"}]
in your php, also return a content type of : application/json
精彩评论