weixin_33728268 2016-10-22 18:13 采纳率: 0%
浏览 34

Ajax数据表无法重新加载

i have made function where i can add a row after confirming. the problem is, after submit button, the tables dont reload and show error function alert.actually data success saved and i have to refresh the page so that the table can reload. here is my ajax jquery code:

function reload_table()
{
    table.ajax.reload(null,false); //reload datatable ajax 
}

function save()
{
    $('#btnSave').text('saving...'); //change button text
    $('#btnSave').attr('disabled',true); //set button disable 
    var url;

    if(save_method == 'add') {
        url = "<?php echo site_url('activity/save')?>";
    } else {
        url = "<?php echo site_url('activity/ajax_update')?>";
    }

    // ajax adding data to database
    $.ajax({
    url : url,
    type: "POST",
    data: $('#form-input').serialize(),
    dataType: "JSON",
    success: function(data)
    {

    if(data.status) //if success close modal and reload ajax table
        {
           $('#myModal').modal('hide');
           reload_table();
              
        }

          $('#btnSave').text('save'); //change button text
          $('#btnSave').attr('disabled',false); //set button enable 


        },
    error: function (jqXHR, textStatus, errorThrown)
      {
         alert('Error adding / update data');
         $('#btnSave').text('save'); //change button text
         $('#btnSave').attr('disabled',false); //set button enable 

        }
    });
}

my controller:

public function save() {
        $actype         = $this->input->post('actype');
        $activity_name  = $this->input->post('activity_name');
        $project        = $this->input->post('project');
        $portion        = $this->input->post('portion');
        $activity       = $this->input->post('actid');


        $data = array(
            'activity_type_id'  =>$actype,
            'activity_name'     =>$activity_name,
            'project_id'        =>$project,
            'portion'           =>$portion,
            'activity_id'       => $activity
            
        );
        $this->activity->insertactivity($data);

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

how can i automatically reload only the datatables and show alert success.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 关于logstash转发日志时发生的部分内容丢失问题
    • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
    • ¥15 微信会员卡接入微信支付商户号收款
    • ¥15 如何获取烟草零售终端数据
    • ¥15 数学建模招标中位数问题
    • ¥15 phython路径名过长报错 不知道什么问题
    • ¥15 深度学习中模型转换该怎么实现
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 如何用python向钉钉机器人发送可以放大的图片?