C
C
Caspergreen2016-05-17 13:55:03
MySQL
Caspergreen, 2016-05-17 13:55:03

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

Right now it just prints an error or success in #response.
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'>&times;</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

1 answer(s)
R
Rou1997, 2016-05-17
@Rou1997

Well, the block should be loaded from the database, either just when the page is reloaded, or by AJAX, although why AJAX, this is not a chat.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question