I have two select lists. I am making an ajax call to populate them with .append() and have tried both $.ajax and $.getJson to assess synchronous and asynchronous options. Using either call type I can get, in the same session with and withouth browser refresh:
- Both populated
- One but not the other
- Neither
The server response is coming back with valid JSON.
Below is the ajax call with loop. I have no console errors, stepping through server-side is fine. I am not sure how to debug this further and looking for some guidance.
$.ajax({
url: "/Programs/GetAll",
contentType: "json",
method: "GET",
success: function (data) {
//iterate over the data and append a select option
$.each(data, function (key, val) {
$('#programId').append('<option id="' + val.id + '">' + val.name + '</option>');
})
}
});
If there is something wrong in the ajax call or better practice I would be keen to learn that as well.
Thanks all.
EDIT
Having wrapped the ajax calls in $(selector).length, despite being visible in the UI, it is returning false so my assumption is that they are not available to jQuery to append.
The select lists are in a Bootstrap modal, as below.
BootstrapDialog.show({
type: BootstrapDialog.TYPE_DANGER,
title: '<i class="fa fa-calendar"></i> Create Event',
message: '<p><i class="fa fa-clock-o"></i> ' + _when_ + '</p>' +
'<select required id="programId" class="calendar_event_input_add form-control"></select>' +
'<select required id="taskId" class="calendar_event_input_add form-control"></select>' +
'<input required type="text" id="apptEventTitle" class="form-control" placeholder="Short Name" />' +
'<textarea required type="text" id="apptEventDescription" class="calendar_event_textarea_add form-control" placeholder="Good Description" rows="3"/></textarea>' +
'<input type="text" class="calendar_event_input_add form-control" id="apptEventUrl" placeholder="Reference Link" />' +
'<input type="hidden" id="apptStartTime" value="' + start + '" />' + /** start date hidden **/
'<input type="hidden" id="apptEndTime" value="' + end + '" />' + /** end date hidden **/
'<input type="hidden" id="apptAllDay" value="' + allDay + '" />' + /** allday hidden **/
'',
buttons: [
{
label: '<i class="fa fa-check"></i> Create Event',
cssClass: 'btn-success',
hotkey: 13, // Enter.
action: function (dialogItself) {
_calendarEventAdd();
dialogItself.close();
_calendarInstance.fullCalendar('unselect');
}
},
{
label: '<i class="fa fa-times"></i> Cancel',
cssClass: 'btn-default',
action: function (dialogItself) {
dialogItself.close();
_calendarInstance.fullCalendar('unselect');
}
}
]
});