How to populate a dropdownlist with json data in jquery?

后端 未结 4 1235
挽巷
挽巷 2020-11-30 02:49

I am developing a country state cascading dropdown list... I returned json result based on countryId but I don\'t know how to populate/fill it in a new dropdown

相关标签:
4条回答
  • 2020-11-30 03:01
    //javascript
    //teams.Table does not exist
    
    function OnSuccessJSON(data, status) {
        var teams = eval('(' + data.d + ')');
        var listItems = "";
        for (var i = 0; i < teams.length; i++) {
          listItems += "<option value='" + teams[i][0]+ "'>" + teams[i][1] + "</option>";
        }
        $("#<%=ddlTeams.ClientID%>").html(listItems);
    } 
    
    0 讨论(0)
  • 2020-11-30 03:06

    To populate ComboBox with JSON, you can consider using the: jqwidgets combobox, too.

    0 讨论(0)
  • 2020-11-30 03:09
    var listItems= "";
    var jsonData = jsonObj.d;
        for (var i = 0; i < jsonData.Table.length; i++){
          listItems+= "<option value='" + jsonData.Table[i].stateid + "'>" + jsonData.Table[i].statename + "</option>";
        }
        $("#<%=DLState.ClientID%>").html(listItems);
    

    Example

       <html>
        <head></head>
        <body>
          <select id="DLState">
          </select>
        </body>
        </html>
    
        /*javascript*/
        var jsonList = {"Table" : [{"stateid" : "2","statename" : "Tamilnadu"},
                    {"stateid" : "3","statename" : "Karnataka"},
                    {"stateid" : "4","statename" : "Andaman and Nicobar"},
                     {"stateid" : "5","statename" : "Andhra Pradesh"},
                     {"stateid" : "6","statename" : "Arunachal Pradesh"}]}
    
        $(document).ready(function(){
          var listItems= "";
          for (var i = 0; i < jsonList.Table.length; i++){
            listItems+= "<option value='" + jsonList.Table[i].stateid + "'>" + jsonList.Table[i].statename + "</option>";
          }
          $("#DLState").html(listItems);
        });    
    
    0 讨论(0)
  • 2020-11-30 03:18

    try this one its worked for me

    $(document).ready(function(e){
            $.ajax({
               url:"fetch",
               processData: false,
               dataType:"json",
               type: 'POST',
               cache: false,
               success: function (data, textStatus, jqXHR) {
                            
                             $.each(data.Table,function(i,tweet){
    			   $("#list").append('<option value="'+tweet.actor_id+'">'+tweet.first_name+'</option>');
    			});}
            });
        });

    0 讨论(0)
提交回复
热议问题