我正在执行此代码,尽管它会产生错误。
function getUserPosts(){
$.get("../php/PostHandler.php", function(data) {
var posts = JSON.parse(data);
alert(posts);
for(var x = lastNumPosts; x <= posts.length; x++){
var postLine = "<div class='user-post'><div class='user-p-info'><img src='imgs/email-icon2.png'><h2> "+ posts[x].name +" </h2><br> <small>Posted Tuesday 23/10</small></div><div class='user-p-content'><p>" + posts[x].pContent + "</p></div></div>";
$('.post-zone').prepend(postLine);
}
});
}
TypeError:帖子[x]未定义
有解决方案吗?
答案 0 :(得分:0)
更改此行:
for (var x = lastNumPosts; x < posts.length; x++) {
通知<
而不是<=
。