在学习html表中输出JSON数组, 文章https://www.it1352.com/960539.html给出了很好的示例。出于调试方便,最后一段代码做了修改如下
<script>
$(document).ready(
function() {
var table = $('<table/>').appendTo($('#somediv'));
$.getJSON('servlet/json_show', function(persons) { //servlet/json_show换成自己的
console.log(persons);
$.each(persons, function(i, person) {
console.log(person.name);
$('<tr/>').appendTo(table).append(
$('<td/>').text(person.name)).append(
$('<td/>').text(person.address));
});
});
});
</script>
这样在浏览器中按F12调试,尽可以看到服务器段返回的数据了。
原文代码persons.each(function(i, person)需要修改为$.each(persons, function(i, person) 。