jeudi 21 mai 2020

Yajra Datatable return Invalid JSON response

I use Yajra Datatable in my Laravel Project . I created my DataTable with it and it works correctly for me. But sometimes it gives me the error that by refreshing the page a few times this error will be fixed! Where is the problem?

Error:

DataTables warning: table id={id} - Invalid JSON response.

this is my datatable config :

   let table = $('.data-table').DataTable({
            processing: true,
            serverSide: true,
            "language": {
                "infoFiltered":   "(جستجو شده  از _MAX_  پیام)",
                "lengthMenu":     "نمایش _MENU_ پیام",
                "search": "جستجو",
                "processing":"درحال پردازش",
                "emptyTable":'پیامی یافت نشد',
                "infoEmpty":"نمایش 0 پیام از 0 پیام ",
                "loadingRecords":"درحال بارگزاری ",
                "zeroRecords":"پیامی با این نام یافت نشد",
                "info": "نمایش صفحات _PAGE_ از _PAGES_",
                "paginate": {
                    "first":      "اولین",
                    "last":       "آخرین",
                    "next":       "بعدی",
                    "previous":   "قبلی"
                },
            },
            ajax: "",
            columns: [
                {data: 'DT_RowIndex', name: 'DT_RowIndex'},
                {data: 'title', name: 'title'},
                {data: 'date', name: 'date'},
                {data: 'from', name: 'from'},
                {data: 'action', name: 'action', orderable: false, searchable: false},
            ]
        });

this is my Controller : ( Index )

  public function index(Request $request)
    {
        if ($request->ajax()) {
            $data=null;
            if(auth()->user()->hasRole('admin'))
                $data=Message::all();
            else{
                $data=Message::where('pid',auth()->user()->pid)->get();
            }
            return Datatables::of($data)
                ->addIndexColumn()
                ->addColumn('action', function($row){
                    $btn='<a href="javascript:void(0)" class="edit btn btn-success btn-sm" id="'.$row->id.'">  مشاهده</a>';
                    return $btn;
                })
                ->addColumn('date', function ($row){
                    return Helpers::shamsi($row->created_at);
                })
                ->addColumn('from', function ($row){
                    return User::where('pid',$row->pid)->first()->name;
                })
                ->rawColumns(['action'])
                ->make(true);
        }
        return view("common.message");


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2XuEc3x
via IFTTT

Aucun commentaire:

Enregistrer un commentaire