Answer the question
In order to leave comments, you need to log in
How to update a block after adding a record to the database, ajax?
I am writing comments on the post, I need to update the comment block after the comment is added by users.
Ajax
$(document).ready(function (){
$("#comment").submit(function (e){
e.preventDefault();
$("#loader").show();
var url = $(this).attr('action');
//var data = new FormData($('#update')[0]);
var data = $('#comment').serialize();
$.ajax({
url:url,
type:'POST',
data:data
}).done(function (data){
$("#response").html(data);
$("#loader").hide();
});
});
});
public function save_comment(){
//$this->form_validation->set_error_delimiters("<span class='error'>", "</span>");
$this->load->library('users/auth');
$this->set_current_user();
$this->form_validation->set_rules('comment', 'Комментарий', 'required');
$this->form_validation->set_rules('series_id', '', 'numeric');
if($this->form_validation->run() === FALSE){
/*return false;*/
echo "
<div class='alert alert-block alert-error fade in'>
<a class='close' data-dismiss='alert'>×</a>
<h4 class='alert-heading'>
".lang('series_errors_message')."
</h4>
".validation_errors()."
</div>";
} else {
$this->series_model->save_comment();
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question