I using Jquery autocomplete and I have the following code:
Client side:
$( "#tags" ).autocomplete({
source: function(request, response) {
$.ajax({
url: "get_professionals",
data: request,
dataType: "json",
type: "POST",
success: function(data){
alert("hello");
}
});
}
});
Server side:
function get_professionals() {
if ($_POST["term"]):
$professionals = Professional::find('all', array('conditions' => "name LIKE '%" . $_POST["term"] . "%'"));
foreach ($professionals as $professional):
echo $professional->to_json();
endforeach;
endif;
}
the URL is right and, in fact, I get the results from server(I checked it from Firebug in “post” tab) but does not shows
The autocomplete requires a
labeland/orvaluefield to be returned in the data.Adjust your query to return what you want in the autocomplete in
valueand/orlabelfields.Or, some other method to return values like the bolded example from the documentation above. For example, you could set the
labelandvaluefields in the success function: