0
只有在尚未完成時纔想填充選擇#current_location
。僅在選項標記不存在時填充選擇
$(document).ready(function(){
$('#current_location').on('change', function(){
/*
* Populate the select
* I want to populate the select only if it hasn't been done yet
*/
$.getJSON('fetch.php', {action: 'homepage' , key: 'current_location' }, function(data){
var options = '';
for (var x = 0; x < data.length; x++) {
options += '<option value="' + data[x] + '">' + data[x] + '</option>';
}
$('#current_location').html(options);
});
$.getJSON('fetch.php', {action: 'homepage' , key: $('#current_location').val() }, function(data){
var options = '';
for (var x = 0; x < data.length; x++) {
options += '<option value="' + data[x] + '">' + data[x] + '</option>';
}
$('#destination').html(options);
});
});
});
@SougataBose發帖作爲答案,以便我可以關閉這個 – user2650277