weixin_33726313 2013-11-16 07:48 采纳率: 0%
浏览 32

评论删除无效

I'm trying to perform a delete of a forum comment using Jquery AJAX and PHP(codeigniter) with Datamapper but for some reason no matter what I do nothing happens when I click delete.

If anyone can see the problem that'd be great.

Jquery =

$('button.delete').on('click', function(event) {

    console.log('derp');
    // var comment = $(this).parent('.comment').attr('id');

    // $.post('actions/delete_comment/'+comment);

});

forum post php =

<li class="comment" id="<?=$comment->id ?>">
    <img  src="assets/img/avatars/<?=$comment->user.'.jpg' ?>">
    <p class="username"><?=$comment->user ?></p><p class="commenttime"><?=$comment->date ?></p><br>
    <p><?=$comment->contents ?></p>
    <button class="delete">Delete</button>
</li>

delete php =

public function delete_comment($id){
    $comments = new Forum_comment;
    $comments->get_where(array('id' => $id));
    $comments->delete();
}
  • 写回答

4条回答 默认 最新

  • weixin_33721427 2013-11-16 07:50
    关注

    You commented out all of the actual code in your jQuery event, except for the console.log()

    $('button.delete').on('click', function(event) {
    
        console.log('derp');
        var comment = $(this).parent('.comment').attr('id');  // Remove leading slashes
    
        $.post('actions/delete_comment/'+comment);  // Remove leading slashes
    
    });
    

    Of course nothing happens!

    评论

报告相同问题?

OSZAR »