Home > OS >  exception: "Symfony\Component\HttpKernel\Exception\NotFoundHttpException",…
exception: "Symfony\Component\HttpKernel\Exception\NotFoundHttpException",…

Time:11-06

I am a newbie to jquery and ajax and I am using laravel in my backend,"I must say the codes below works perfectly fine for just one of my pages but other pages I get the error above". I tried to load my jquery datatables data via ajax so I performed a jquery ajax call to my route as below:

ajax:
    
        {
            type    : "get",
            url     : "{{URL::asset('AgencyExpenses')}}",
            dataType: "json",
        },
        columns: 
        [
            {"data":"id"},
            {"data":"agency_id"},
            {"data":"amount"},
            {"data":"date"},
            {"data":"description"},
            {"data":"address"},
            {
                "data": null,
                render: function(data,row,type){
                    return '<button class="btn btn-trans btn-sm btn-primary fa fa-pencil text-primary" data-toggle="collapse" data-target="#collapsable" ></button>'
                }
                
            },
            {
                "data": null,
                render: function(data,row,type){
                    return '<button class="btn btn-trans btn-sm btn-danger fa fa-trash text-danger"></button>'
                }
                
            },
        ],
        autofill: true,
        select: true,
        responsive: true,
        buttons: true,
        length: 10,
    }
    

my "web.php" route is:

Route::get('AgencyExpenses',[AgencyExpController::class, 'expense']);

and my controller returns this function:

public function expense()
{
    $expense = AgencyExp::all();
    return response()->json([
        'data' => $expense,
    ]);
}

but every time the page loads this message displays: jquery datatable error

in network the fetch/xhr returns 404 status code with the following exceptions:

"", exception: "Symfony\Component\HttpKernel\Exception\NotFoundHttpException",…}

CodePudding user response:

I had to clear the routes cache by executing two command listed below:

php artisan optimize

and

php artisan route:clear

CodePudding user response:

Named routes allow the convenient generation of URLs or redirects for specific routes. You may specify a name for a route by chaining the name method onto the route definition:

Route::get('AgencyExpenses',[AgencyExpController::class, 'expense'])
    ->name('agency.expense');

Try to change your AJAX URL :

{
    type    : "get",
    url     : "{{ route('agency.expense') }}",
    dataType: "json",
},

PS : Don't forget to clear route :

php artisan route:clear
  • Related