yajra / laravel-datatables

jQuery DataTables API for Laravel
https://yajrabox.com/docs/laravel-datatables
MIT License
4.74k stars 862 forks source link

Ajax Request Code 403 Forbidden But Response is Success #1709

Closed hendripr93 closed 1 year ago

hendripr93 commented 6 years ago

Summary of problem or feature request

Ajax Request in Cpanel show error like this "DataTables warning: table id=dynamic-table - Ajax error. For more information about this error, please see http://datatables.net/tn/7", with status code "403 Forbidden" but response data is normally.

Code snippet of problem


//MyController
public function GetData(Request $request)
    {
        $Role=Auth::user()->RoleID;
        $ShipTo = $request->ShipTo;
        $reseller = $request->reseller;
        $No=1;
        $data="";
        $no=0;
        DB::statement(DB::raw('set @rownum=0'));
        $data=DB::table('salesorder as so')->select(DB::raw('@rownum  := @rownum  + 1 AS rownum'),'so.*','c.Name As CustName','c.Address AS Address','c.Tlp AS Tlp','bo.IsBelanjuk AS IsBelanjuk','bo.BelanjukStatus as BelanjukStatus','bo.Remark as BoRemark')
            ->leftjoin('billingorder as bo','bo.OrderNumber','=','so.OrderNumber')
            ->join('customer as c','c.CustomerID','=','so.ShipTo')
            ->where('so.ResellerID','LIKE',$reseller.'%')
            ->where('c.Name','LIKE','%'.$ShipTo.'%')
            ->where('so.IsSubmit',1)
            ->where('so.IsPaid',1)
            ->where('so.IsConfirmed',1)
            ->where('so.IsProcessed',1)
            ->where('so.OnDelivery',1)
            ->where('so.Status','OnDelivery')
            ->where('so.IsClosed',0)
            ->where('so.IsDecline',0)
            ->where('so.IsExpired',0)
            ->where('bo.IsPaid',1)
            ->where('bo.IsApprove',1)
            ->orderby('so.OrderNumber', 'ASC');
        // dd($data);
        return Datatables::of($data)
            ->addColumn('StatusStr', function($data){ 
                    return 'Paid';
            })
            ->addColumn('action', function($data){ 
                return '<a class="btn btn-xs btn-warning btn-round" href="javascript:void(0)" title="Track Kiriman" onclick="Track('."'".$data->OrderNumber."'".')"><i class="glyphicon glyphicon-search"></i> Track</a> <a class="btn btn-xs btn-primary btn-round" href="javascript:void(0)" title="Edit Resi" onclick="Edit_resi('."'".$data->OrderNumber."'".')"><i class="glyphicon glyphicon-pencil"></i> Ubah Resi</a>';
            })

            ->addColumn('No', function($data){ 
                return 1;
            })
            ->addColumn('GrandTotalStr', function($data){ 
                return "Rp. ".number_format($data->GrandTotal,0,'',',');
            })
            ->addColumn('Service',function($data){
                $TrimRemark=str_replace(" ","",$data->BoRemark);
                $CekJNTSHOPEE=substr($TrimRemark,0,9);
                if(strtoupper($CekJNTSHOPEE)=="JNTSHOPEE")
                {return 'JNT SHOPEE';}
                else if(strtoupper($data->ShippingName)=="ONSITE")
                {return '<span class="badge badge-danger">ONSITE</span>';}
                else
                {return $data->ShippingName."-".$data->ShippingService;}
            })
            ->addColumn('checkbox', function($data){
                return '<input type="checkbox" class="data-check" value="'.$data->OrderNumber.'" Name="BulkOrderNumber[]"></input>';
            })
            ->rawColumns(['Service', 'action','checkbox'])
            ->make(true);
    }
//My Jquer Ajax
var myTable;
    jQuery(function($) {
        myTable = 
        $('#dynamic-table').DataTable({
            serverSide: true,
            processing: true,
            ajax: {
                "url": "{{url('OnDeliveryOrders/GetData')}}",
                'headers': {
                    'X-CSRF-TOKEN': '{{ csrf_token() }}'
                    },
                "data": function ( data ) {
                    data.reseller = $('#reseller').val();
                    data.ShipTo = $('#ShipTo').val();
                }
            },
            columns: [
                {data: 'checkbox',"bSortable": false, "orderable": false, "searchable" :false},
                {data: 'rownum', "searchable" :false},
                { "data": null, "class": "details-control", "defaultContent": "", "orderable": false, "searchable" :false},
                {data: 'OrderNumber',name:'so.OrderNumber', autowidth:true},
                {data: 'ResellerID',name:'so.ResellerID'},
                {data: 'Service',name:'so.ShippingName'},
                {data: 'CustName',name:'c.Name'},
                //{data: 'GrandTotalStr'},
                {data: 'ShippingNumber',name:'so.ShippingNumber'},
                {data: 'Status',name:'so.Status'},
                {data: 'action', "searchable" :false},
            ],
            fnRowCallback: function (nRow, aData, iDisplayIndex, iDisplayIndexFull) {
                if (parseInt(aData["IsBelanjuk"])==1 ) 
                {
                    $('td', nRow).css('color','red');
                }
                else
                {
                    $('td', nRow).css('color','black');
                }
            }
        });

<!--
If applicable, please include a copy of your code
which triggers the suspected bug.

You may use the markdown php code tags to format your paste:

```php
$params = ['foo'];

-->

System details

Skintillion commented 6 years ago

Please remove the personal information in your 'response'.

supermariobros0xx commented 4 years ago

Please delete this thread because leak some people information, including my friend information. Thans

hendripr93 commented 4 years ago

Ok, response has been deleted... thanks all

eggy4prlnt commented 1 year ago

any solution?

hendripr93 commented 1 year ago

issue closed, but I forgot the solution. which is clearly related to the hosting server that I use.

hendripr93 commented 1 year ago

any solution?

I just remembered, the problem is because of modsecurity features. after I disabled it, everything was back to normal.

ahmedrakha10 commented 1 year ago

@hendripr93 i have the same problem , what is the solution , although it is working fine but in another hosting server