Quote:Is there any chance to submit the comment in ajax
Sure, in order to do that, first alter this line:
PHP Code:
echo form_input('post_comment[]',NULL,'size="40" class="ta-comment"');
into:
PHP Code:
echo form_input('post_comment[]',NULL,'size="40" class="ta-comment" postid="' . $row->post_id . '"');
Then, in the script section, make the following changes:
Code:
<script>
$('.ta-comment').keypress(function(event) {
if (event.which == 13 ) {
event.preventDefault();
url = "<?= base_url();?>regcheck/ajax_comment_insert";
ctext = $(this).val();
postid = $(this).attr('postid');
$.ajax({
url : url,
type: "POST",
data : { comment: ctext, post_id: postid }
});
}
});
</script>
And finally, you need to add a new method to your controller Regcheck, to make it insert the posted comment:
PHP Code:
public function ajax_comment_insert()
{
$data = array(
'post_id' => $this->input->post('post_id'),
'comment' => $this->input->post('comment')
);
$this->db->insert('post_comments',$data);
}