【发布时间】:2021-10-04 04:23:48
【问题描述】:
我正在尝试连接所有 94 个结果并将其返回到 #title1。
下面的所有代码在运行时显示信息方面都可以正常工作,而不是在用户单击按钮时返回每个国家/地区的 94 行。我试图让它在 countryName 标记上循环并添加到结果数组中,一旦循环在国家 94 结束,然后将其推送到 #title1。
有什么帮助吗?
$('#PostalCodeCountryInfoBtn').click(function() {
$.ajax({
url: "libs/php/getPostalCodeCountryInfo.php",
type: 'GET',
dataType: 'json',
success: function(result) {
console.log(JSON.stringify(result));
if (result.status.name == "ok") {
$('#title1').html(result['data'][0]['countryName'] + " " + result['data'][1]['countryName']);
$('#title2').html(result['data'][1]['countryName']);
$('#title3').html(result['data'][2]['countryName']);
$('#title4').html(result['data'][3]['countryName']);
$('#title5').html(result['data'][4]['countryName']);
$('#title6').html(result['data'][94]['countryName']);
}
},
error: function(jqXHR, textStatus, errorThrown) {
// error code
}
});
});
【问题讨论】:
标签: javascript jquery json ajax