Click here to Skip to main content
15,918,303 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
Hello guys hope you can give me an idea or any "Working Sample" on how to create an autocomplete using jquery.. i have some sample but its not working

$(function() {
    $( "#city" ).autocomplete({
        source: function( request, response ) {
            $.ajax({
                url: "http://ws.geonames.org/searchJSON",
                dataType: "jsonp",
                data: {
                    featureClass: "P",
                    style: "full",
                    maxRows: 12,
                    name_startsWith: request.term
                },
                success: function( data ) {
                    response( $.map( data.geonames, function( item ) {
                        return {
                            label: item.name + (item.adminName1 ? ", " + item.adminName1 : "") + ", " + item.countryName,
                            value: item.id,
                            source: item
                        }
                    }));
                }
            });
        },
        minLength: 2,
        change: function(event, ui) {
           if (ui.item) {
              $('#your_hidden_input').val(ui.item.source.id);
              $(this).val(ui.item.value);
           }
        }
    });
});


Based from this line

url: "http://ws.geonames.org/searchJSON",


when i type in it should go to http://ws.geonames.org/searchJSON but the problem is when i type in my value it goes to this url

http://mysite.com/undefined?query=myqueryvalue"


and help and idea is very much appreciated guys thanks in advance
Posted
Updated 4-Sep-11 19:59pm
v2
Comments
Sergey Alexandrovich Kryukov 5-Sep-11 12:37pm    
What's "not working"?
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900