我在尝试从我的 PHP 服务器检索 Ajax 数据时遇到了一个奇怪的问题。当我从下拉菜单中选择一个国家时,country_id 会记录在控制台中,并且数据也会显示在控制台中。但是,由于某种原因,如果我尝试在成功函数中提醒返回的数据,我什么也得不到。事实上,如果我尝试在成功功能中提醒任何内容,它不会显示。有什么我想念的小东西吗?我的代码如下。提前致谢。
$("#country_id").change(function() {
var country_id = $(this).val();
console.log(country_id);
$.ajax({
type: 'POST',
url: 'register/load-zones',
data: {country_id: country_id},
beforeSend: function() {
// $('#ajax-panel').html('<div class="loading"><img src="/images/loading.gif" alt="Loading..." /></div>');
},
success: function(zones) {
console.log(zones);
var zoneSelect = $('#zone_id');
zoneSelect.empty();
zoneSelect.append($('<option/>').attr('value', '').text('Select State'));
$.each(zones, function (index, zone) {
zoneSelect.append($('<option/>').attr('value', zone.zone_id).text(zone.name));
});
},
error: function() {
// $('#ajax-panel').html('<p class="error"><strong>Oops!</strong> Try that again in a few moments.</p>');
},
dataType: JSON
});
});