Sanjeewa Sanjeewa - 1 year ago 113
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 () {

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 Source

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


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


(documented on the same page).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download