当我尝试使用ajax请求方法“ post”获取数据时,出现NotFoundHttpException
这是路线(web.php)
Route::prefix('shoppingcart')->group(function() {
Route::middleware(['auth','roles:1,2,3'])->group(function () {
Route::get('/', 'ShoppingCartController@index')->name('shoppingcart');
Route::get('/create', 'ShoppingCartController@create')->name('shoppingcart.create');
Route::post('/store', 'ShoppingCartController@store')->name('shoppingcart.store');
Route::post('/getProducts/{id}', 'ShoppingCartController@getProducts');
});
});
控制器
public function getProducts($id){
$data['products'] = DB::table('products')
->join('entity_localizations' , 'entity_localizations.item_id', '=', 'products.id')
->select('products.id as id',
DB::raw('coalesce((entity_localizations.value),products.name) as name'),'products.price as price')
->where('entity_localizations.entity_id', '=', Helper::getEntityId("Product")->id)
->where('products.product_department_id', '=', $id)
->get();
return $data;
}
index.blade.php js部分
$('#result').on('click', function(){
var val = 3;
var _token = '{{csrf_token()}}';
$.ajax({
type:'POST',
url:'getProducts/'+val,
dataType:'JSON',
data:{_token:_token},
success: function(data){
console.log(data);
},
});
});