Click here to Skip to main content
15,919,132 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I got undefined in dropdown

JavaScript
<script type="text/javascript" >

    $(function () {
        $.ajax({
            type: "POST",
            contentType: "application/json; charset=utf-8",
            url: 'WebServices/AutoComplete.asmx/GetCountries',
            data: "{}",
            datatype: "json",
            success:
                function (data, event) {


                    $.map(data.d, function (item) {
                    //    alert(item);
                        //                        $("#<%= drpCountry.ClientID %>").index = item.countryid;
                        //                        $("#<%= drpCountry.ClientID %>").val = item.countryname;
                                      alert(item.countryname);

                        $("#<%= drpCountry.ClientID %>").append("<option value="+item.countryid+" >"+item.countryname+"</option>");

                    });
                }

        });

    });           
    
                   </script>
Posted
Comments
ZurdoDev 15-Jan-13 9:19am    
Put a breakpoint and see what you are getting.

1 solution

XML
<script type="text/javascript" >

    $(function () {
        $.ajax({
            type: "POST",
            contentType: "application/json; charset=utf-8",
            url: 'WebServices/AutoComplete.asmx/GetCountries',
            data: "{}",
            datatype: "json",
            async: true,
            cache: true,
            success:
                function (data, event) {


                    $.map(data.d, function (item) {
                    //    alert(item);
                        //                        $("#<%= drpCountry.ClientID %>").index = item.countryid;
                        //                        $("#<%= drpCountry.ClientID %>").val = item.countryname;
                                      alert(item.countryname);

                        $("#<%= drpCountry.ClientID %>").append("<option value="+item.countryid+" >"+item.countryname+"</option>");

                    });
                }

        });

    });

                   </script>
 
Share this answer
 

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