简体   繁体   English

异常:“Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException”,...

[英]exception: "Symfony\Component\HttpKernel\Exception\NotFoundHttpException",…

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".我是 jquery 和 ajax 的新手,我在后端使用 laravel,“我必须说下面的代码仅适用于我的一个页面,但其他页面出现上述错误”。 I tried to load my jquery datatables data via ajax so I performed a jquery ajax call to my route as below:我试图通过 ajax 加载我的 jquery 数据表数据,所以我对我的路由执行了 jquery ajax 调用,如下所示:

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:我的“web.php”路线是:

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但每次页面加载时都会显示此消息: jquery datatable error

in network the fetch/xhr returns 404 status code with the following exceptions:在网络中,fetch/xhr 返回 404 状态代码,但有以下例外:

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

I had to clear the routes cache by executing two command listed below:我必须通过执行下面列出的两个命令来清除路由缓存:

php artisan optimize

and

php artisan route:clear

Named routes allow the convenient generation of URLs or redirects for specific routes.命名路由允许为特定路由方便地生成 URL 或重定向。 You may specify a name for a route by chaining the name method onto the route definition:您可以通过将 name 方法链接到路由定义来为路由指定name

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

Try to change your AJAX URL :尝试更改您的 AJAX 网址:

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

PS : Don't forget to clear route : PS:不要忘记清除路线:

php artisan route:clear

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 异常“Symfony\\\\Component\\\\HttpKernel\\\\Exception\\\\NotFoundHttpException” - exception "Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException" CSRF 令牌不匹配。”,异常:“Symfony\Component\HttpKernel\Exception\HttpException - CSRF token mismatch.", exception: "Symfony\Component\HttpKernel\Exception\HttpException 将JavaScript添加到PHP表单会引发Symfony \\ Component \\ HttpKernel \\ Exception \\ MethodNotAllowedHttpException - Adding JavaScript to PHP form throws Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException Symfony\\Component\\HttpKernel\\Exception\\MethodNotAllowedHttpException-laravel 5.7.28 - Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException- laravel 5.7.28 Laravel 5.7引发Symfony \\ Component \\ HttpKernel \\ Exception \\ MethodNotAllowedHttpException调用更新函数时没有消息错误 - Laravel 5.7 throws Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException No message error on calling update function React Native 中的组件异常? - Component Exception in React Native? React Native - 组件异常 - React Native - Component Exception React Native,组件异常 - React Native, Component Exception 组件初始化因NoProvider异常而失败 - Component Initialization failing with NoProvider exception 组件异常元素类型无效 - Component exception Element type is invalid
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM