0
$(document).on('focus', '.resource_person', function() {
var topic_code = $(this).attr('id');
var rp_reference = $(this).attr('selected-rp');
var option = '';
$.ajax({
type: 'POST',
url: siteUrl + 'course_management/Training_courses/topic_rp',
data: {topic_code: topic_code},
dataType: 'json',
success: function(source) {
$('.resource_person[id="'+topic_code+'"]').empty();
for (var key in source) {
if (source[key] != rp_reference) {
option += '<option value="'+source[key]+'">'+key+'</option>';
} else {
option += '<option value="'+source[key]+'" selected="">'+key+'</option>';
}
}
console.log(option);
$('.resource_person[id="'+topic_code+'"]').append(option);
}
});
});
This what was happening when I first click the dropdown使用追加()
After clicking it for the second time it goes back to the normal behavior of dropdown
「注意:將緩存設置爲false只能正確處理HEAD和GET請求。」就像在http://api.jquery.com/jquery.ajax/ –
上說的那樣,但是你給了我一個主意,謝謝你。我通過點擊加載來解決我的問題,這樣下拉菜單在append之前不會顯示它的內容。 –
@LemuelDoronio感謝您指出'注意' –