当前位置: 动力学知识库 > 问答 > 编程问答 >

jquery loads the same posts instead of appending new ones

问题描述:

I am able to display first two posts and a button "Load more" but when I press "Load more" button it still gets the same two posts.

Could you please have a look on my code and help me to find the mistake.

 $("#load_more_posts").click(function() {

var offset = offset+limit;

$.post('cont/get_list', {limit: limit, offset: offset}, function (data) {

if (data.message !== undefined) {

$( "#list_is_not_got").text(data.message);

} else {

var item = $('<div>');

$.each(data.results, function(i, res) {

var info = $('<p>');

info.html(res.post_text+'<hr>');

item.append(head,info);

});

$("#list_is_got").html(item);

}

}, "json");

});

网友答案:

Probably to do with failure to increment offset.

Try changing :

var offset = offset + limit;

to :

offset += limit;
分享给朋友:
您可能感兴趣的文章:
随机阅读: