0

I'm getting a JSON array from server :

mysql_select_db('******') or die("Error connecting to db.");
$res = mysql_query("SELECT DISTINCT(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...

2
  • Could you provide more information? ie. What plugin are you using for autocomplete? What's c? Commented Apr 22, 2011 at 9:01
  • I'm using jquery ui autocomplete, i don't knows what c is, it's a jquery core variable. Commented Apr 22, 2011 at 9:17

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.