2

I have a simple Laravel app with a single data table that processes data serverside and serves it to the page. It uses a package, yajra/laravel-datatables. This works fine when testing locally (php artisan serve), but when the app is hosted I get an error on page load:

DataTables warning: table id=program-table - Ajax error. For more information >about this error, please see http://datatables.net/tn/7

and my request returns a 404 in the dev tools. I assume this issue sprouts somewhere in the routing, as the server is hosted with IIS and has several rewrite rules- although disabling them hasn't had any effect.

My laravel route looks like:

Route::get('/serverSide', [
  'as'   => 'serverSide',
  'uses' => function () {
    $model = \App\Degree::query();
    return DataTables::eloquent($model)->toJson();
  }
]);

And my DataTable setup is:

    $('#program-table').DataTable({
  processing: true,
  serverSide: true,
  ajax: "{{ route('serverSide') }}",
  columns: [
      {
        "className":      'details-control',
        "orderable":      false,
        "data":           null,
        "width":          '5%',
        "searchable":     false,
        "defaultContent": ''
      },
      { data: 'cip', width: '10%'},
      { data: 'cip_title' },
      { data: 'item_name' },
      { data: 'degree_name_list' },
      { data: 't_state_code_list', width: '7%' },
      { data: 'p_state_code_list', width: '7%' },
      { data: 's_state_code_list', width: '7%' }
  ],
  pageLength: 25,
  searching: true,
  paging: true,
  "order": [[ 1, "asc" ]]
});

If anyone has any experience with a similar issue or solution I would be happy to know! Thank you very much

2 Answers 2

4

The URL is probably too long for IIS (IIS has a limit in bytes on the URL length). If you look in the IIS logs for your site, you should see a 404.15 or 404.14 for the request.

If you open the network tab in the DEV tools of your browser, check the length of the GET request when you open the Datatable.

IIS default limit is 4kb IIRC. Work out the length you need. My limit is 10KB, 10240 bytes.

In IIS:

  1. go to your site:
  2. Open Request Filtering -> Edit Feature Settings (menu on right hand pane).
  3. Change Max URL length and Max Query String to your required value (mine is 10240).
  4. Restart the site.
Sign up to request clarification or add additional context in comments.

1 Comment

I've been stuck for days. Your solution have saved my days. Thanks
0

I had the same problem. Making requests by using "post" instead of "get" is fixed the problem. You can use the following code to make post requests.

$('#users-table').DataTable({
        processing: true,
        serverSide: true,
        ajax: {
            url: 'http://datatables.yajrabox.com/eloquent/column-search-data',
            method: 'POST'
        }
});

Source: https://github.com/yajra/laravel-datatables/issues/74#issuecomment-111974122

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.