评论删除无效

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

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!

You need to ensure that the elements you are selection with $('button.delete) actually exist when jQuery is called. Either move your Javascript to the bottom of your <body>, or wrap the javascript in a domReady function:

$(document).ready(function() {

$(button.ready)...// do your initialisation here.

});

In addition to have commented out the actual code that does what you want it to do, you also haven't defined an id attribute for the li tag with class 'comment'.

So in this case var comment = $(this).parent('.comment').attr('id'); will return nothing.

The li tag needs to be <li class="comment" id=(insert_comment_id_here)>

try this in your jquery

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

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

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

});

and ofcourse uncomment the code please when it start getting into the event handler..