How to populate dropdownlist with JSON data as ajax response in jQuery

后端 未结 7 1243
梦谈多话
梦谈多话 2021-02-05 14:47

I am working on a j2ee application. In my application I have a drop-down list(or Select element). I want to populate this drop-down list with JSON data as a Ajax response.

7条回答
  •  终归单人心
    2021-02-05 15:24

    try to change the jquery method variable, it might be causing the problem (i.e., you are using the data variable coming from the ajax callback PLUS are then trying to assign it to the item object in the jquery method - changed to obj):

            $.ajax({
                type: "GET",
                url:"/demo_trial_application/json_source",
                dataType: "json",
                success: function (data) {
                    $.each(data.aaData,function(i,obj)
                    {
                     alert(obj.value+":"+obj.text);
                     var div_data="";
                    alert(div_data);
                    $(div_data).appendTo('#ch_user1'); 
                    });  
                    }
              });
            });
    

提交回复
热议问题