I'm using this plugin here: http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/
I have this:
function formatar(result) {
return result.q + ' (teste ko)';
}
$(document).ready(function() {
$('#nome_dominio').autocomplete("testeJson2.php", {
parse: function(data) {
alert(data);
//what now?
},
formatItem: function(result) {
return formatar(result);
}
}).result(function(e, result) {
alert ('you have choose something');
});
});
If we alert(data), we DO get the results exactly like so:
[{"nomeDominio":"aaaa.hk"},{"nomeDominio":"agentesdeexecucao.hk"}]
I believe the next step should be parse this value in a way the plugin understands?
Can I have a push please? Thanks in advance, MEM
1 Answer 1
I would move to the officially supported jQuery autocomplete plugin - http://jqueryui.com/demos/autocomplete/
It is actually based off of the plugin you are using above so it should not be a great effort to upgrade. The page linked above has detailed examples of remote datasources and how to parse the data for the plugin.
In general you want the source to be a simple array - so if you can modify the server-side code this would be a more ideal returning JSON object:
["aaaa.hk","agentesdeexecucao.hk"]
You could also write some JavaScript to convert the returning JSON objects into a single array.