2013-03-04 124 views
0

嗨,即时通讯使用codeigniter和内置ajax无限滚动。并在该Ajax滚动评论形式,我担心的是页面加载时,10个职位将被加载,如果向下滚动另一个10职位将被加载,现在所有20个职位将包含自己的评论形式。即时通讯使用Ajax发表评论。所以对于页面加载的评论表单正在工作但加载了ajax的帖子的第10条帖子,评论表单ajax帖子不起作用。下面是我使用的代码。Ajax加载的表单不通过ajax发布数据

<script type="text/javascript"> 
$('.post_comment').click(function() { 
    var form_data = { 
    csrfsecurity: $(this).parent().find("input[name=csrfsecurity]").val(), 
    post_text: $(this).parent().find('.comment_text').val()  
    }; 

    $.ajax({ 
    url: "<?php echo site_url('/comment'); ?>", 
    type: 'POST', 
    data: form_data, 
    success: function(response){ 
     $(".home_user_feeds").html("markUpCreatedUsingResponseFromServer"); 
    } 
    }); 
    return false; 
}); 
</script> 

当页面向下卷动

<form action="http://localhost/comment" method="post" accept-charset="utf-8"> 
<input type="text" name="comment_text" value="" id="comment_text" size="35" class="comment_text"> 
<input type="submit" id="post_comment" name="post_comment" value="submit comment" class="post_comment" > 
</form> 
+0

我的猜测是你没有将事件监听器添加到你正在AJAX中的HTML中。前10个工作是因为你正在为文档加载中的原始10添加事件监听器。 – thatidiotguy 2013-03-04 19:27:22

+0

该怎么办? @thatidiotguy – 2013-03-04 19:29:02

+0

可能的重复[Ajax无限滚动jquery不适用于窗体从ajax加载](http://stackoverflow.com/questions/15208990/ajax-infinite-scroll-jquery-not-work-for-forms-loaded- from-ajax) – Musa 2013-03-04 19:32:21

回答

0

我的猜测是,你是不是添加事件监听器,你中AJAXing的HTML以下表格将加载10次。你的前十位的工作,因为您正在文档加载中添加原始10的事件侦听器。

您将需要运行jQuery代码,将事件处理程序添加到DOM元素(具有类post_comment的元素看起来像)再次单击事件。

+0

@thatidotguy请问您可以发布代码。 – 2013-03-04 19:34:17

+0

@vinothkumar什么?你已经有了代码。你写了吗? – thatidiotguy 2013-03-04 19:48:07

+0

我非常感谢你 – 2013-03-04 19:52:50