json, ajax + autocomplete tutorial

I would really appreciate if anyone has time to give an example of using json, ajax and autocomplete.

I would like to be able to have a field in a form which is city, when the user types a city name it is passed to the json url and then ajax or autocomplete is populated with the possible options.


I sm starting to think that I might be asking stupid questions as I never get any responses!!! :blink:

I am going to attempt to do this myself and post and get some feed back. cheers

There a cookbook example using CAutoComplete, here. It looks a bit full of holes, though.

Thanks auxbuss… I found the same thing and am also of the same opinion. I haven’t had a chance to work on anything yet but am hoping to post some results soon. I’m sure this would be a popular tutorial amongst the yii community.

Cheers again

Were you thinking of an example that uses CAutoComplete or raw jQuery?

I have to confess that I don’t mind XML returns from AJAX calls. Using SimpleXML makes for neat code server side, and then it’s easy to step through the return with something like this, which hides all the XMLness:

$(xmlDoc).find('document').each(function() {

    display += '<tr><td>' + $('title', this).text()   + '</td>' +

                <td>'     + $('product', this).text() + '</td>' +

               '<td>'     + $('date', this).text()    + '</td></tr>';

} );

JSON going in can be handy, though.