【发布时间】:2019-10-09 04:39:57
【问题描述】:
我从console.log() 的 AJAX 响应中获得 3 个对象。但是,网站中只有一个数据显示为输出。
我尝试使用$.each 来响应来自 AJAX 的响应,但它只显示来自一个对象的数据。我希望网站中显示所有三个对象的数据。
$.ajax({
url: '/process/archiveFull1.php',
type: 'POST',
data: {
id: 2018,
},
success: function(response) {
if (typeof(response) != 'object') {
response = $.parseJSON(response);
}
if (response.status.status == true) {
$.each(response.body, function(key, value) {
html_option = "<div class='carousel-inner'><div class='carousel-item active'><div class='top-with-controls-archive text-center'>" + value.id + "</h4></div><div class='body-archive'><div class='row py-2'><div class='col-md-3 col-sm-6'><a href='" + value.added_date + "'><img src='" + value.image + "' class='img-fluid'></a></div></div></div>";
});
$('#wrap').html(html_option);
}
}
});
【问题讨论】:
-
请注意对问题中的代码进行格式化,使其易于阅读。我已经为你编辑了它
-
关于这个问题,你能告诉我们
response的内容到底是什么样子的吗 -
@RoryMcCrossan 添加问题时,我无法按 ctrl+k。
-
@RoryMcCrossan 我已添加收到的回复