嗨,即时通讯使用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>
我的猜测是你没有将事件监听器添加到你正在AJAX中的HTML中。前10个工作是因为你正在为文档加载中的原始10添加事件监听器。 – thatidiotguy 2013-03-04 19:27:22
该怎么办? @thatidiotguy – 2013-03-04 19:29:02
可能的重复[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