php – How do i insert data using ajax in JQGrid with CI?-ThrowExceptions

Exception or error:

i try to learn JQGrid but i still dont understand how to insert/edit/delete using ajax from JQGrid i try learn from here http://js-tutorials.com/demos/jqgrid_jquery_add_edit_example_demo/ ,when i try add ajax , its doesnt work at all here mmy code

this is the funtion for insert

    function tambah_data(){

    $data = array(
        'nama' => $this->input->post('nama'),
        'deskripsi'=>$this->input->post('deskripsi'),
        'user_id'=>$this->input->post('user_id'),
        'created_time'=>$this->input->post('created_time')
        );

}

this is for model

function insert_mtk($data) {
    return $this->db->insert('master_matakuliah',$data);
}

this is y JQGRID

$("#photos").jqGrid({
    url:'<?php echo base_url().'index.php/Welcome/lihat_data'?>',
    datatype: "json",
    colNames:['ID','NAMA','DESKRIPSI', 'USER ID', 'DATE CREATED'],
    colModel:[
        {name:'id',index:'id', width:55, editable: false},
        {name:'nama',index:'nama', width:55, editable: true},
        {name:'deskripsi',index:'deskripsi', width:350, sortable:false, editable: true, edittype:"textarea"},   
        {name:'user_id',index:'user_id', width:300, editable: true},    
        {name:'created_time',index:'created_time', width:300, editable: true, unformat: pickDate},  
    ],
    rowNum:10,
    loadonce: true,
    rowList:[10,20,30],
    pager: '#pager2',
    sortname: 'id',
    viewrecords: true,
    sortorder: "desc",
    caption:"",
    editable: true
});

this is my ajax ( but i stil dont know where to put ajax inside JQGrid or outside then making function)

    function AddPost(params) {
    var selr = $('#grid-table').jqGrid('getGridParam','selrow'); 
    var id = $('#grid-table').getCell(selr, 'id');

    $.ajax({
        type: "POST",
        url : '<?php echo base_url() ?>index.php/Welcome/tambah_data',//something is saved
        dataType: "JSON",
    })
    console.log(params);                

}
How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *