I configured the following route in my route file:
Route::post('order/productsByCategory', ['uses'=>'OrderController@productsByCategory']);
How do I use it in my Ajax request?
$.ajax({
url: "",
type: 'POST',
data: "",
headers: {
'X-CSRF-Token': laravel_token
},
dataType: 'JSON',
success: function (data) {
console.log(data);
}
});
EDIT : I changed the route to:
Route::post('Order/productsByCategory', ['as' => 'productsByCategory', 'uses'=>'OrderController@productsByCategory']);
And the requisition for:
$.ajax({
url: '{{ route("productsByCategory") }}',
type: 'POST',
data: { id: categoryId},
dataType: 'JSON',
headers: {
'X-CSRF-Token': laravel_token
},
success: function (data) {
debugger;
console.log(data);
}
});
However, the following error occurred:
POST http://localhost/manapasteis2/public/%7B%7B%20route(%22productsByCategory%22)%20%7D%7D 403 (Forbidden)