[英]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.