Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

datatables warning ajax error 404 not found #717

Closed
ghost opened this issue Aug 28, 2016 · 10 comments
Closed

datatables warning ajax error 404 not found #717

ghost opened this issue Aug 28, 2016 · 10 comments
Labels

Comments

@ghost
Copy link

ghost commented Aug 28, 2016

Summary of problem or feature request

I am new to laravel. I was able to run datatable using jquery plugin.
I would like the server side processing. I encountered error 404 the other day. Today I encountered
500 Internal Server Error. Call to undefined method Yajra\Datatables\Datatables:

  • Call to undefined method Yajra\Datatables\Datatables::eloquent() is present. Yesterday it was 404 file not found. Please help me fix error so that I can run server side processing. I am unable to see what causes this. Could it be that I am using sorting and search in my index?
  • I also tried to check the demo regarding left join however was unable to get the demo.
    An accession has categories and so need a join. **_How do you output data that comes from a join
    in the columns? Can you provide simple example for join used in server side processing?
  • How about if you also need a view and edit button in the columns, how do you place them?

Thank you for looking at this.

Code snippet of problem

image
here is route..
image
index.blade.php
image
service provider
image
alias
image

then accession

public function index(Request $request){

    $categories = Category::all();

    $query = Accession::select('*');

    //this is for links that will run query according to
    //category type

    if ($request->input('type')){

        switch ($request->input('type')){

            case 'Photo':

                $query->where('category_id', 2);

                break;

            case 'Field Notes':

                $query->where('category_id', 3);

                break;

            case 'Audio Recording':

                $query->where('category_id', 4);

                break;

            case 'Instrument':

                $query->where('category_id', 5);

                break;

            case 'Music Scores':

                $query->where('category_id', 6);

                break;

            case 'Video':


                $query->where('category_id', 7);

                break;

            case 'Vertical Files':

                $query->where('category_id', 8);

                break;

            default:

                $query->orderBy('id', 'asc')->get();
        }

        $accessions = $query->orderBy('id')->get();
        return view('accessions.index', compact('accessions', 'categories'));


    }

    //this is for search bar

    $search = $request->input('search'); //<-- we use global request to get the param of URI

    if($search){

        $accessions = Accession::where('groupcountry','LIKE','%'.$search.'%')
                    ->orWhere('description', 'LIKE', '%'.$search.'%')
                    ->orWhere('author', 'LIKE', '%'.$search.'%')
                    ->orWhere('accession_no','LIKE','%'.$search.'%')
                    ->orWhere('year','LIKE','%'.$search.'%')
                    ->paginate(10);

        return view('accessions.index', compact('accessions', 'categories'));
    }
    else{


        $accessions = Accession::orderBy('id', 'asc')->get();
        return view('accessions.index', compact('accessions', 'categories'));
    }


}

System details

  • Operating System Windows 10
  • PHP Version PHP 5.6.20
  • Laravel Version Laravel Framework version 5.2.45
  • Laravel-Datatables Version 6.0
@ghost
Copy link
Author

ghost commented Aug 29, 2016

I changed the namespace to use Yajra\Datatables\Facades\Datatables;
Tables are now showing up hoewever received error.

image

the error is error 200

@yajra
Copy link
Owner

yajra commented Aug 29, 2016

Try inspecting the ajax response to get a better view of the error. You may also need to double check that your columns and your js match your table structure. This is probably a js issue.

@yajra yajra added the question label Aug 29, 2016
@ghost
Copy link
Author

ghost commented Aug 29, 2016

Thank you for the response. Yes I have checked the ajax response. JSON lint looks good. The error 200 disappeared. I checked the columns and js and match them with table structure. So far error now is

image
Will double check

image

image

image

@ghost ghost changed the title Call to undefined method Yajra\Datatables\Datatables::eloquent() in C: datatables warning ajax error 404 not found Aug 29, 2016
@yajra
Copy link
Owner

yajra commented Aug 29, 2016

404 Not Found is an intermittent issue of dataTables due to environment issue when using php artisan serve. Please use valet, homestead or wamp/xampp to avoid this issue.

@ghost
Copy link
Author

ghost commented Aug 29, 2016

@yajra . Yes. I am currently using xampp. Search continues

@ghost
Copy link
Author

ghost commented Aug 30, 2016

Route definition has been reviewed. Intermittent 404 but ajax returns data. I think I have to agree on environment issue.

@ghost
Copy link
Author

ghost commented Aug 31, 2016

Deployed the app live in heroku. 404 is gone. So this is confirmed environment issue. Closing this. @yajra Thank you for looking at the error. Your documentation also helped me with left join and view and edit button, Thank you.

@NightravenJames
Copy link

The solution given above works just transfer your project to the HTDOCS of your XAMPPor www of your WAMPP or run it live

@Akashdb5
Copy link

Akashdb5 commented Jul 9, 2019

@Marker17 just make your javascript and web.php as follows

 $(document).ready(function () {
    var table = $('#example').DataTable({
        dom: 'lBrtip',
        processing: true,
        serverSide: true,
        ajax: {
            'url':'{!!url("ajax/chapter/list")!!}',
            'type': 'POST',
            'headers': {
            'X-CSRF-TOKEN': '{{ csrf_token() }}'
            }
            },

        orderCellsTop: true,
        fixedHeader: true,

        "columns": [{
                data: 'DT_RowIndex',
                orderable: false,
                searchable: true
            },

            {data: 'stream_id'},
            {data: 'course_id'},
            {data:  'subject_id'},
            {data:  'chapter_name'},
            {data: 'status'},
            {data: 'edit_delete',orderable: false},
        ],
    });

});

And in web.php

Route::any('ajax/chapter/list','YourController@Method');

this code worked for me.

@qahwarizmi
Copy link

@Marker17 just make your javascript and web.php as follows

 $(document).ready(function () {
    var table = $('#example').DataTable({
        dom: 'lBrtip',
        processing: true,
        serverSide: true,
        ajax: {
            'url':'{!!url("ajax/chapter/list")!!}',
            'type': 'POST',
            'headers': {
            'X-CSRF-TOKEN': '{{ csrf_token() }}'
            }
            },

        orderCellsTop: true,
        fixedHeader: true,

        "columns": [{
                data: 'DT_RowIndex',
                orderable: false,
                searchable: true
            },

            {data: 'stream_id'},
            {data: 'course_id'},
            {data:  'subject_id'},
            {data:  'chapter_name'},
            {data: 'status'},
            {data: 'edit_delete',orderable: false},
        ],
    });

});

And in web.php

Route::any('ajax/chapter/list','YourController@Method');

this code worked for me.

save my day

@github-actions github-actions bot locked and limited conversation to collaborators Oct 19, 2022
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants