Filling SelectList with javascript cshtml

Filling SelectList with javascript cshtml

本文关键字:cshtml javascript with SelectList Filling      更新时间:2023-09-26

我试图从客户端填写一个SelectList。这是我的代码。

function loadSched() {
            var dsId = $(this).val();
            $('#ScheduleId option:not(:first)').remove();
            $.get('/Appointments/GetSchedulesForDoctor?docId=' + dsId)
            .success(function (gn) {
                // alert('start');
                $.each(gn, function () {
                    $('#ScheduleId').append($('<option/>', { value: this.Value }).text(this.Text));
                });
                // alert('end');
            });
        };
        function initCreate() {
            $('#DoctorId').on('change', loadSched);
        };
        $(document).ready(function () {
            initCreate();
        });

/Appointments/GetSchedulesForDoctor?docId=此路径正确返回json。所以这没有问题。我正在尝试的是填充#ScheduleId时,#DoctorId的变化。开发控制台发现错误是Uncaught TypeError: $.get(...).success is not a function(…)

我做错了什么?相同类型的函数在另一个项目中工作

在jQuery 3中,从$.get(url)返回的jqXHR实例中删除了以下函数:

jqXHR.success();
jqXHR.error()
jqXHR.complete()

jqXHR文档中的弃用通知说要使用以下方式:

jqXHR.done()
jqXHR.fail()
jqXHR.always() 

$.each(gn, function () {
    var option = $("<option>");
    option.attr("value", this.Value).attr("text", this.Text);
    $('#ScheduleId').append(option);
});