jquery每个函数在$ .ajax()成功内部都不起作用

时间:2013-04-27 05:52:33

标签: php jquery ajax load each

我在一个页面上有一个评论sscript,其中包含一个主要问题,他们的答案就像堆栈溢出一样。 对于每个答案,还有一个评论脚本。在加载问题页面时,每个答案都会使用以下代码加载注释

$(document).ready(function(){

    $('.disagree_comments').each(function(){
    $(this).load("includes/disagree_comments_loader.php?aid="+$(this).parents('.answer_text').children('.agree_disagree_main_cont').children('#answer_id').val());
   });
});

但是当我对ajax成功做同样的事情时,我做错了是不行或者有不同的方法可以做到这一点吗?

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

    $.ajax({
        type: 'POST', 
        url: 'includes/reply_editor.php', 
        data: "comment="+$('#comment_text_update').val()+"&id="+$('#commentid_edit').val(),
        success: function(){
            $('#comment_text_update').val('');
            $('#commentid_edit').val('');
            $('.comment_edit_transparent_layer').css('display','none');


                $('.disagree_comments').each(function(){
                    $(this).load("includes/disagree_comments_loader.php?aid="+$(this).parents('.answer_text').children('.agree_disagree_main_cont').children('#answer_id').val());
                });

        }
    });


});

2 个答案:

答案 0 :(得分:0)

data: "comment="+$('#comment_text_update').val()+"&id="+$('#commentid_edit').val(),

应该是

data: {comment:$('#comment_text_update').val(),id:$('#commentid_edit').val()},

答案 1 :(得分:0)

定位错误的div $(。disagree_comment)正确的是$(' .answer_agree_disagree_review')

修改代码:

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

$.ajax({
    type: 'POST', 
    url: 'includes/reply_editor.php', 
    data: "comment="+$('#comment_text_update').val()+"&id="+$('#commentid_edit').val(),
    success: function(){
        $('#comment_text_update').val('');
        $('#commentid_edit').val('');
        $('.comment_edit_transparent_layer').css('display','none');


           $('.answer_agree_disagree_review').each(function(){
                        $(this).load("includes/answer_reply_loader.php?aid="+$(this).parents('.answer_text').children('.agree_disagree_main_cont').children('#answer_id').val());
                });
            });

    }
});


});