you are getting an object
in your response, but you need an array
for autocomlete to work. if you can access your backend, you have to fix it there, otherwise, you have to iterate your AJAX' return value and try to convert the object into an array.
Javascript doesn't understand the concept of PHPs associative
arrays, and as JSON is JAVASCRIPT object notation, JSON doesn't understand them either. You have to make sure that your array is a simple array ( i.e. no forced array keys) when you use PHPs json_encode
, or you will get an object in JSON instead of an array.
$a = array("1"=>"one", "3"=>"three");
echo json_encode($a)
// {"1":"one", "3"=>"three"}
// doesn't work for jQuery.autocomplete
$b = array(array("id"=>"1", "label"=>"one"), array("id"=>"3","label"=>"three"));
echo json_encode($b);
// [{"id":1, "label":"one"}, {"id":3, "label":"three"}]
// works for jQuery.autocomplete