【发布时间】:2019-01-05 22:18:53
【问题描述】:
我正在使用 Ajax 和 PHP 在数组 result1 和 result2 中从数据库中获取多个表数据,并且我正在尝试在我希望表的第一个 tr 作为组列的表中显示 result2 数据。
这就是想要的结果。
JS 脚本
function getResult(id = null) {
if(id) {
$.ajax({
url: 'fetch.php',
type: 'post',
data: {id: id},
dataType: 'json',
success:function(response) {
$("#Id").html(response.result1.id);
$("#client").html(response.result1.client);
$("#reg_Date").html(response.result1.reg_Date);
$("#due_date").html(response.result1.due_date);
response.result2.forEach(function(element) {
console.log(element);
var category = element.category;
var names= element.name;
var Result = element.result;
$('table tr').length;
html = '<tr>';
html += '<td><p>'+category+'</p></td>';
html += '</tr>';
$('table').append(html);
$('table tr').length;
html = '<tr>';
html += '<td><p>'+names+'</p></td>';
html += '<td><p>'+Result+'</p></td>';
html += '</tr>';
$('table').append(html);
});
}
});
} else {
alert('error');
}
}
【问题讨论】:
标签: javascript ajax html-table