Javascript 无法使用Ajax填充DropDownList

Javascript 无法使用Ajax填充DropDownList,javascript,c#,jquery,asp.net,ajax,Javascript,C#,Jquery,Asp.net,Ajax,我正在尝试使用Ajax填充DropDownList。我的代码如下。我已经完成了所有的代码,所有的代码都正常工作,没有任何明显的C或Jquery错误。在按钮上单击Jquery运行并调用MyWebMethod。在我的C代码中命中GetLanguageList断点,并成功返回6个对象的列表。success函数遍历6个对象中的每一个。但是,下拉列表仍为空。我没有使用更新面板 我已尝试将返回类型更改为Array和List of ListItem。我尝试使用AjaxControlToolkit组合框而不是D

我正在尝试使用Ajax填充DropDownList。我的代码如下。我已经完成了所有的代码,所有的代码都正常工作,没有任何明显的C或Jquery错误。在按钮上单击Jquery运行并调用MyWebMethod。在我的C代码中命中GetLanguageList断点,并成功返回6个对象的列表。success函数遍历6个对象中的每一个。但是,下拉列表仍为空。我没有使用更新面板

我已尝试将返回类型更改为Array和List of ListItem。我尝试使用AjaxControlToolkit组合框而不是DropDownList。我试着在documentready上填充DropDownList,而不是单击按钮。我为DropDownList的DataText和DataValue属性添加了文本和值

还有什么可能导致DropDownList无法填充

我的方法

    [WebMethod()]
    public static ArrayList GetLanguageList()
    {
        ArrayList lstArrLanguage = new ArrayList();
        lstArrLanguage.Add(new ListItem("C#", "C#"));
        lstArrLanguage.Add(new ListItem("Java", "Java"));
        lstArrLanguage.Add(new ListItem("PHP", "PHP"));
        lstArrLanguage.Add(new ListItem("VB.NET", "VB.NET"));
        lstArrLanguage.Add(new ListItem("JavaScript", "JavaScript"));
        lstArrLanguage.Add(new ListItem("jQuery", "jQuery"));
        return lstArrLanguage;
    }
我的Jquery

    <script language="javascript" type="text/javascript">

         $(function() {
            $("#locationList").change(function () {
                TestMethod();
            }).change();
        });

        function TestMethod() {
            $.ajax({
                type: "POST",
                url: '<%= ResolveUrl("EmailEditor.aspx/GetLanguageList") %>',
                data: '',
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function(msg) {
                    $("#DropDownList1").empty().append($("<option></option>").val("[-]").html("Please select"));
                    $.each(msg.d, function() {
                        $("#DropDownList1").append($("<option></option>").val(this['Value']).html(this['Text']));
                    });
                },
                error: function (xhr) {
                    alert(xhr.responseText);                      
                }
            });
        };
    </script> 
 <asp:Button ID="Button1" OnClientClick="TestMethod()" runat="server" Text="Button" />
 <asp:DropDownList ID="DropDownList1" runat="server">

尝试将成功功能更改为以下内容:

success: function(msg) {
    $("#<%= DropDownList1.ClientID %>").empty().append($("<option></option>").val("[-]").html("Please select"));
    $.each(msg.d, function() {
       $("#<%= DropDownList1.ClientID %").append($("<option></option>").val(this['Value']).html(this['Text']));
    });
}

当页面呈现时,能否验证asp DropDownList控件的ID实际上是DropDownList 1?根据我的经验,asp控件的id与指定的id相似,但不完全相同。您可能需要使用$'[ID*= DROPLISTLIS1] ]来对元素进行定位。使用$来引用下拉ID。当您调用WebMode并在代码后面使用断点时,它会停在这里???您应该考虑重构$Ajax调用以使用承诺而不是配置参数。有关用法示例,请参阅文档。来自jQuery的网站:弃用通知:从jQuery1.8开始,jqXHR.success、jqXHR.error和jqXHR.complete回调已弃用。要准备代码以便最终删除,请改用jqXHR.done、jqXHR.fail和jqXHR.always。来源:@jacob,我会调查的谢谢。谢谢你的提示。我一定是疯了,错过了那个。