views:

26

answers:

1

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

A: 

Hello MEM,

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.

Andrew Wirick
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
MEM
Andrew, I do have ["aaaa.hk","agentesdeexecucao.hk"] now. What should the next step be?
MEM