寻找代码失败的地方

see this HTML markup:

<input value="9961" name="c_id" id="c_id" type="hidden">
<input name="user_id" id="user_id" value="1" type="hidden">
<textarea id="comments" name="comments" style="width: 310px; resize: none; height: 75px"></textarea>

Then I write this code in jQuery to send this data through .post:

$("#dialog-form").dialog({
    autoOpen: false,
    height: 220,
    width: 350,
    resizable: false,
    modal: true,
    buttons: {
        "Ok": function () {
            if ($('#comments').val() != '') {
                $.post("<?php echo site_url('wall/comment') ?>", {
                    value: $("#comments").val(),
                    user_id: $('#user_id').val(),
                    c_id: $("#c_id").val(),
                    is_post: true
                });
                $(this).dialog("close");
                $(location).attr('href', "<?php echo site_url(); ?>");
            }
        },
        "Cancelar": function () {
            $(this).dialog("close");
        }
    },
    close: function () {
        $("#comments").val("");
    }
});

But for some reason isn't working but because I use .post method I can't find where it fails meaning if is jQuery or if it's the server side part.

EDIT This is the PHP code that gets data and run the queries that basically is a INSERT:

    public function comment() {
        role_or_die('wall', 'comment', site_url(), lang('wall:no_permissions'));

        $message = $this->input->post('value', TRUE);
        $post_id = $this->input->post('c_id', TRUE);
        $user_id = $this->input->post('user_id', TRUE);

        $this->load->library('user_agent');
        $device = "";

        if ($this->agent->is_browser()) {
            $device = $this->agent->browser();
        }

        if ($this->agent->is_mobile()) {
            $device = $this->agent->mobile();
        }

        if ($this->wall_comment_m->insert(array('friend_id' => $user_id, 'message' => $message, 'post_id' => $post_id, 'device' => $device))) {
            $this->session->set_flashdata('success', lang('message:comment_add_success'));
        } else {
            $this->session->set_flashdata('error', lang('message:comment_add_error'));
        }
    }

I can't see if the SQL generated is the mistake or if data isn't set at server side because of the location.href.

How I can find where it fails? Any method or something tool to get this done?

$.post is asynchronous. That means that it runs in the background.

So, the $(location).attr('href', "<?php echo site_url(); ?>"); will run before the POST finishes.

You need to use $.post's callback.

var that = this;
$.post("<?php echo site_url('wall/comment') ?>", {
    value: $("#comments").val(),
    user_id: $('#user_id').val(),
    c_id: $("#c_id").val(),
    is_post: true
}, function(){
    $(that).dialog("close");
    $(location).attr('href', "<?php echo site_url(); ?>");
});