mardi 3 septembre 2019

How to solve datatable 403 forbidden in production Laravel?

I have some code to request datatable via jquery ajax that returns:

403 forbidden

in a production environment, it's working properly in my local environment.

Error snap

When I open url directly in browser it shows JSON array.

JSON array snap

this is my ajax request:

$(function(){
        $.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            }
        });
        var state = true;
        var otable = $('#example').DataTable({
            processing: true,
            serverSide: true,
            ajax: "",
            columns: [
                { data: 'CountryCode', name: 'CountryCode' },
                { data: 'CountryName', name: 'CountryName' },
                { data: 'FgActive', name: 'FgActive' },
                { data: 'action', name: 'action' }
            ]
        });

my route

Route::get('get-data-my-datatables', [
    'as'=>'get.data',
    'uses'=>'CountryController@getData'
]);

Below is function in controller

public function getData()
{
    $country = Country::all();

    return datatables()
       ->of($country)
       ->addColumn('action', function ($country) {
           return 
               '<button type="button" name="'.$country->CountryCode.'" class="btn btn-primary btn-sm fa fa-pencil" id="btnEdit" data-toggle="modal"></button>
               <button type="button" name="'.$country->CountryCode.'" class="btn btn-danger btn-sm fa fa-trash" id="btnDel" data-toggle="modal"></button>'
           ;

    })
    ->make(true);
}

Thank you for your attention.


Update

As requested, this is my network tab:

snap network tab



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire