【问题标题】:Incrementally loading items from ajax using jquery使用 jquery 从 ajax 增量加载项目
【发布时间】:2011-10-31 05:51:02
【问题描述】:

谁能帮我写这个小代码?我试图在页面启动时加载项目列表,然后当用户单击更多时,将逐步加载更多项目。

$(document).ready(function(){
    $.get('videos.php', { id: "<?php echo $ID; ?>", start: 0 }, function(data) {
        $('#list').html(data);
    });
});

$('.showmorevids').click(function() {
    var $input = $('.showmorevids span').attr('id').split('-');
    alert(input);
    $.get('videos.php', { id: input[0], start: input[1], total: input[2] }, function(data) {
        $('#list').html(data);
        alert("success");
    });
});

videos.php 页面将返回一个项目列表和一个具有不同 id (id-start-total) 的新按钮,以便我可以将其用作新请求的新变量。第一个 $.get 在页面加载时加载得很好,但是当用户单击按钮获取更多时,没有任何反应,没有发送请求。谁能告诉我我错过了什么?

【问题讨论】:

    标签: jquery ajax


    【解决方案1】:

    使用 live('click') 代替 click()。您不能使用 click() 绑定到动态加载的内容。这很可能是jQuery click event doesn't work the second time的副本

    【讨论】:

      猜你喜欢
      • 2012-11-20
      • 1970-01-01
      • 2012-10-20
      • 1970-01-01
      • 2021-11-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多