0

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

asked Aug 31, 2010 at 13:44

1 Answer 1

0

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.

answered Aug 31, 2010 at 13:51
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your reply Andrew, Unfortunately is not that simple the switch. :( This is a well formed json: [{"nomeDominio":"aaaa.hk"},{"nomeDominio":"agentesdeexecucao.hk"}] And I intend to get used to work with well formed jsons. "You could also write some JavaScript to convert the returning JSON objects into a single array." That seems to be the best option here. Where should I look at in order to accomplish that? K. Regards, MEM
Andrew, I do have ["aaaa.hk","agentesdeexecucao.hk"] now. What should the next step be?

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.