【问题标题】:DataTables warning: table id=courses - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1 [closed]DataTables 警告:表 id=courses - 无效的 JSON 响应。有关此错误的更多信息,请参阅 http://datatables.net/tn/1 [关闭]
【发布时间】:2022-01-13 04:35:22
【问题描述】:

我正在使用有时会显示错误的 php 项目:

DataTables 警告:表 id=courses - JSON 响应无效。有关此错误的更多信息,请参阅http://datatables.net/tn/1

以前它运行良好,如图所示: previous image

但从昨天开始,它说错误:images present

但是这个错误永远不会经常发生,有时它会起作用,有时它会显示错误我无法识别错误是什么。

**here is the ajax which i used**

var table = $('#courses').DataTable({
    "processing": true,
    "serverSide": true,
   "ajax":{
         "url": _base_url + 'admin/Course/posts',
         "dataType": "json",
         "type": "POST",
         "contentType": "application/json; charset=utf-8",
         "data": { },
         
         // "success":function(result)
         // {
         //    console.log(result);
         // }
      },

    "columns": [
              { "data": "id" },
              
              { "data": "status" },
              { "data": "name" },
              { "data": "image" },
              { "data": "actions" },

           ],

           "columnDefs": [ {
                      "targets"  : '',
                      "orderable": false,
                      
                    }
                    ],
    rowReorder: {
        dataSrc: 'sort_order'
    }


});

这里是控制器:

public function posts()
{
    $columns = array( 
                        0 =>'id', 
                        1 =>'name',
                    );

    $limit = $this->input->post('length');
    $start = $this->input->post('start');
    $order = $columns[$this->input->post('order')[0]['column']];
    $dir = $this->input->post('order')[0]['dir'];
    $modeType  = "online"; 
    
    $totalData = $this->Course_model->getcountcourseAndBooks('courses');
    $totalFiltered = $totalData; 
    if(empty($this->input->post('search')['value']))
    {            
        $posts = $this->Course_model->getLimitOrderBy('courses',$limit,$start,$order,$dir);
    }
    else 
    {
        $search = $this->input->post('search')['value']; 
        $posts =  $this->Course_model->posts_search($limit,$start,$search,$order,$dir);          
        $totalFiltered = $this->Course_model->posts_search_count($search);
    }

    $data = array();
    if(!empty($posts))
    {
         
        $i= 1;
        foreach ($posts as $post)
        {
            $nestedData['id'] = '<span class="badge badge-primary">'.$post->id.'</span>';
            $i++;
            $check_status = ($post->status == 1) ? 'checked' : '';
            $nestedData['status'] = '<label class="switch">
                                              <input type="checkbox" '.$check_status.' name="admin_active" data-id="'.$post->id.'" value="1" class="custom-control-input status-change" id="customSwitch2_">
                                              <span class="slider round"></span>
                                            </label>';             
            
            $nestedData['name'] = $post->name;

            $nestedData['image'] = '<img src="'.$post->thumb_url.'" style="width:50px;">';
            $nestedData['sort_order'] = '<span class="badge badge-warning">'.$post->sort_order.'</span>';
            // $date  =date("jS F, Y", strtotime($post->created_at));
            // $nestedData['created_on'] = '<i class="fa fa-desktop"></i> '.$date.'<br><br>';

             $nestedData['content_add'] = '<a  href="'.base_url().'admin/chapter/content-add/'.$post->id.'"  "><i class="fa fa-plus text-success fa-lg m-r-10"></i></a>';

             $nestedData['chapter_add'] = '<a  href="'.base_url().'admin/course/course-chapter/'.$post->id.'"  "><i class="fa fa-plus text-success fa-lg m-r-10"></i></a>';

             $nestedData['actions'] = '<a class="pull-right dtldata"  data-link="'.base_url().'admin/course/delete/'.$post->id.'"><i class="fa fa-trash text-danger fa-lg "></i></a><a class="pull-right" href="'.base_url().'admin/course/edit/'.$post->id.'"   data-id="'.$post->id.'"><i class="fa fa-edit text-info fa-lg m-r-10"></i></a>';
             
            
            $data[] = $nestedData;

        }
    }

    
      
    $json_data = array(
                "draw"            => intval($this->input->post('draw')),  
                "recordsTotal"    => intval($totalData),  
                "recordsFiltered" => intval($totalFiltered), 
                "data"            => $data   
                );
        
    echo json_encode($json_data); 
}

这是我收到的帖子错误: ajax post error

谁能建议我是什么导致了错误

【问题讨论】:

标签: javascript php ajax


【解决方案1】:

对于 codeigniter 项目,出现此错误是因为某些库在我的情况下未加载,它是“imagick.so”,因此在 CI 项目的索引文件中只需添加以下行:

$_SERVER['CI_ENV'] = 'production'; //this line
define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'development');

【讨论】:

    猜你喜欢
    • 2019-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多