Ajax-Call: Unexpected Identifer

Ajax-Call: Unexpected Identifer

LaufwerkLaufwerk Posts: 1Questions: 1Answers: 0

Hi, I'm a Newbie with datatables. And I get an error : Unexpected Identifer and nothing happens by showing a users-list.
Whats wrong with ajax: "{{ route('users.index') }}", ?

Route web.php:

Route::get('users', ['uses'=>'UserController@index', 'as'=>'users.index']);

Ajax/js-Aufruf UserController@index

public function index(Request $request)
{

    if ($request->ajax()) {
        $data = User::select('*');
        return Datatables::of($data)
            ->addIndexColumn()
            ->addColumn('action', function($row){})
            ->rawColumns(['action'])
            ->make(true);
    }

    return view('users');
}

View Users.blade.php

var table = $('.data-table').DataTable({
processing: true,
serverSide: true
ajax: "{{ route('users.index') }}",
columns: [
{data: 'id', name: 'id'},
{data: 'name', name: 'name'},
{data: 'email', name: 'email'},

Debugging:

Answers

  • kthorngrenkthorngren Posts: 21,172Questions: 26Answers: 4,923

    You need a comma separating the options:

    serverSide: true  // missing comma on this line
    ajax: "{{ route('users.index') }}",
    

    Kevin

This discussion has been closed.