Sanjeewa Sanjeewa - 1 month ago 22
Javascript Question

Filling SelectList with javascript cshtml

I am trying to fill a SelectList from client side.
This is the code I have.

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=
this path returns json correctly. so no issue with that. what I am trying is fill the #ScheduleId when the #DoctorId changes.
Developer console caught that the error is
Uncaught TypeError: $.get(...).success is not a function(…)


What I am doing wrong? same type of function works in another project.

Answer

In jQuery 3 the following functions were removed from the jQXHR instance returned from $.get(url):

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

the deprecation notice in the jqXHR documentation says to use the following instead:

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

(documented on the same page).