0
votes

I can Load data with ajax but, I can't save data with ajax in ckeditor

Here's my ajax in view

$.ajax({

    url : "<?php echo base_url('admin/perusahaan_baik/edit_narasi_gcg')?>/" + id,
    type: "GET",
    dataType: "JSON",
    success: function(data)
    {

        $('[name="id"]').val(data.id);
        $('[name="posting_date"]').val(data.posting_date);
        $('[name="description"]').val(CKEDITOR.instances.description.setData(data.description));

$('#modal_narasi').modal('show'); // show bootstrap modal when complete loaded $('.modal-title').text('Edit Perusahaan Baik'); // Set title to Bootstrap modal title }, error: function (jqXHR, textStatus, errorThrown) { alert('Error get data from ajax'); } });

Here's my controller

    $data = array(

            'posting_date' => $this->input->post('posting_date'),
            'description' => $this->input->post('description')
        );

    $this->narasi_model->update_narasi_gcg(array('id' => $this->input->post('id')), $data);

    echo json_encode(array("status" => TRUE));

Here's my model

    public function get_by_id($id)
    {
        $this->db->from($this->table);
        $this->db->where('id',$id);
        $query = $this->db->get();

        return $query->row();
    }

    public function update_narasi_gcg($where, $data)
    {
        $this->db->update($this->table, $data, $where);
        return $this->db->affected_rows();  
    }

Here's my div

                    <div class="form-group">
                        <label class="control-label col-md-3">Posisi ID</label>
                        <div class="col-md-9">
                            <textarea name="description" id="description" rows="10" cols="80">

                      </textarea>
                        </div>
                    </div>
2
print_r($_POST) in your controller and check what are you getting in post variable.Naim Malek
In the ajax where is the data is need to send to the controller?Anand Pandey
@NaimMalek ok let me tryAnggrean Sendy
@AnandPandey $('[name="id"]').val(data.id); $('[name="posting_date"]').val(data.posting_date); $('[name="description"]').val(CKEDITOR.instances.description.setData(data.description));Anggrean Sendy
When ajax get data from db than we get this data not at the sending for edit/save.Anand Pandey

2 Answers

0
votes

Add also id and posting_date

<div class="form-group">
<label class="control-label col-md-3">Posisi ID</label>
<div class="col-md-9">
<textarea name="description" id="description" rows="10" cols="80"></textarea>
<input type="hidden" name="posting_date" id="posting_date">
<input type="hidden" name="id" id="id">
</div>
</div>
0
votes

I input this code and it works. Thanks yall

CKEDITOR.instances['description'].on('change',function(){
CKEDITOR.instances['description'].updateElement();
});