2013-04-27 84 views
0

我有一個評論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的成功同樣的事情有不同的methos做這個?

$('#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()); 
       }); 

     } 
    }); 


}); 
+1

什麼意思是不工作 – 2013-04-27 05:54:12

+0

是成功的方法叫做 – 2013-04-27 05:55:11

+0

''answer_id'在'.each()'循環中的事實讓我覺得有多個元素的'id'爲'answer_id',對吧?如果是這樣,那就是你的問題。 – Blender 2013-04-27 05:55:28

回答

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

應該

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

其實數據也在工作它的存儲,事情是不工作的每個功能。它不會再加載每個.disagree_comments元素的註釋。 – 2013-04-27 06:05:18

0

目標定位上錯格$正確的是$

修改代碼(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()); 
       }); 
      }); 

    } 
}); 


});