0

我的代码如下,但它不工作。

var dropdownProgramType = $('#<%=programtypeid.ClientID %>');

dropdownProgramType.change(function () {
    var item = dropdownProgramType.val();

    $("#<%=errormsg.ClientID%>").text(dropdownProgramType.val());

    $.ajax({
        type: "POST",
        url: "dataCheck.aspx/fatchProgramType",
        data: '{item:"' + item + '"}',
        contentType: "application/json; charset=utf-8",
        dataType: "json",

        success: function (data) {

            var programName = $('#<%=programnameid.ClientID %>');

            $.each(response.d, function (index, item) {

                programName.addOption(item.ID, item.Fullname, false);
            });


        },
        error: function () {
            alert(msg.status);
        }
    });
});

但是上面的代码没有显示值

4

2 回答 2

0

试试这个代码你的循环

$(programName).append($("<option></option>").val(item.ID).html(item.Fullname));
于 2013-06-11T06:41:47.943 回答
0

这是我的示例代码

$.ajax({
        type: "POST",
        url: 'addemployee.aspx/BindBranchName',
        data: '{}',
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: OnBranchPopulated,
        failure: function (response) {
            alert(response.d);
        }
    });


 function OnBranchPopulated(response) {
    PopulateinBranchControl(response.d, $("#drpdwnbranchname"));
}
function PopulateinBranchControl(list, control) {
    if (list.length > 0) {
        control.removeAttr("disabled");
        control.empty().append('<option selected="selected" value="0">Please select</option>');
        $.each(list, function () {
            control.append($("<option></option>").val(this['Value']).html(this['Text']));

        });
    }
    else {
        control.empty().append('<option selected="selected" value="0">Not available<option>');
    }
}
于 2013-06-11T07:27:53.570 回答