douxiyi2418 2014-01-21 20:24
浏览 15
已采纳

加载新内容并跟踪最旧的文章[关闭]

I have never actually learned how to create a blog or anything the like up to now. I would like to create a personal portfolio/homepage, which will load older articles as soon as the user pushes the "load more" button. Now, I have it all set up, but I don't really know how to keep track of the oldest article ID.

As mentioned, here I load articles from a php script via AJAX.

$('#more_articles_button').click(function () {

    $.ajax({ url: kBaseUrl+"content_loader.php",
        data: {
               action: 'load_more_articles', 
               article_id: 'insert_lowest_article_id'
        },
        type: 'post',
        success: function(output) {

                 $('#articles_container').append(output);

        }
    });

});

Here I would like to get the last article's id and send it to the php script. How do I get hold of it ?

  • 写回答

1条回答 默认 最新

  • doulei6330 2014-01-21 20:30
    关注

    Put the article id in the id's attribute of your article's div and a common class in them (say, 'article'), and, using JQuery, iterate through them to get the maximum value:

    var max_id = 0;
    $('.article').each(function(i, object) {
        curr_id = $(object).attr('id');
        if (curr_id > max_id)
            max_id = curr_id;
    });
    
    //Afterwards, your ajax JQuery call
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法