ajax数据表无法重新加载

时间:2016-10-22 18:13:44

标签: ajax codeigniter datatables

我已经做了功能,我可以在确认之后添加一行。问题是,在提交按钮后,表格不会重新加载并显示错误功能alert.actually数据成功保存,我必须刷新页面,以便表格可以重新加载。 这是我的ajax jquery代码:



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 

        }
    });
}
&#13;
&#13;
&#13;

我的控制员:

&#13;
&#13;
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));
    }
&#13;
&#13;
&#13; 如何自动重新加载数据表并显示警报成功。

0 个答案:

没有答案