我正在尝试将数据库显示为html页面。数据出现在我的控制台中,但我不知道如何在html表格中显示它。我不确定需要添加到console.log (数据)中的函数才能显示到页面上。这就是我到目前为止所知道的:
<button class="btn btn-primary" id="btn">Get Code</button>
<table class="table table-bordered">
<thread>
<tr>
<th>ID</th>
<th>City</th>
<th>Country</th>
<th>Rating</th>
</tr>
</thread>
<tbody id ="tdata">
</tbody>
</table>
<script>
$(function () {
$.getJSON("php.php", {tableName:"travel"}, function(data){
if (data["code"] == "error"){
console.log(data["message"]);
}
else{
console.log(data);
}
console.log("returned hh");
});
});
console.log("returned");
</script>
</body>
</html>
发布于 2020-01-20 21:11:38
它没有json结构示例,所以您必须用正确的json值名称替换"value.a“。
加载json后:
$.each(data,function(i,value){
$('.table').append('<tr><td>value.a</td><td>value.b</td><td>value.c</td><td>value.d</td></tr>')
})
希望这能有所帮助
https://stackoverflow.com/questions/59668545
复制相似问题