2013-03-08 65 views
0

我无法删除好的评论,它总是删除最后一个。问题jQuery和PHP在对话框中多次提交

我的JS:

$(function() {   
     $(".delete").click(function() { 
      $("#delete-confirm").dialog("open"); 
     }); 

     $("#delete-confirm").dialog({ 
      autoOpen: false, modal: true, width: '600px', show: 'fade', 
      buttons: { 
       "Confimer": function() { 

        $(this).dialog("close"); 
        $('.form-comment').append('<input type="hidden" name="delete" />'); 
        $(".form-comment").submit(); 
       }, 
       "Annuler": function() { 
        $(this).dialog("close"); 
       } 
      } 
     }); 

    }); 

而在PHP:

<?php 
foreach ($commentManager->getList() as $comment) { ?> 
    <form class="form-comment" method="post" style="display: inline;"> 
     <input type="hidden" name="id" value="<?php echo $comment['id']; ?>" /> 
     </form> 
<?php } ?> 

如何提交窗体具有良好ID withtout把我的jQuery代码的PHP页面的中间?

回答

0

我希望我正确理解你的问题,你只想删除选定的评论。所以,你可以尝试这样的:

var goodId = ''; 
$(".delete").click(function() { 
    goodId = $(this).attr('id'); 
    $("#delete-confirm").dialog("open"); 
}); 
// and then later make these changes 
$('.form-comment-'+goodId).append('<input type="hidden" name="delete" />'); 
$(".form-comment-"+goodId).submit(); 
goodId = ''; 

,并在你的PHP代码:

<?php 
foreach ($commentManager->getList() as $comment) { ?> 
    <form class="form-comment-<?php echo $comment['id']; ?>" method="post" style="display: inline;"> 
     <input type="hidden" id="<?php echo $comment['id']; ?>" name="id" value="<?php echo $comment['id']; ?>" /> 
    </form> 
<?php } ?> 

要设置goodId可以使用value属性,如果你想获得评论ID。

+0

Thx寻求帮助。 – kesm0 2013-03-08 04:00:31

0

我想,如果你做的,这将是更好的AJAX请求刚刚获得当前点击DOM

,并分配attr-table-id它然后使用$(this).data('table-id');并通过AJAX发送到服务器

如果你不“不想使用AJAX,做一个重定向,而不是形式提交下沉的问题,因为你要提交各种形式与类form-comment(Use window.location)

我希望这可以帮助