1
I set 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’ve changed course 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);
}
});
But the following mistake happened:
POST http://localhost/manapasteis2/public/%7B%7B%20route(%22productsByCategory%22)%20%7D%7D 403 (Forbidden)
I believe it is
$.ajax({
 url: "/order/productsByCategory",
, the bar at the beginning is to avoid the relative path, if it works let me know– Guilherme Nascimento
which file extension q has the js code?
– gmsantos
The file is . js even @gmsantos
– Jonathan Barcela
Killed the riddle! See @Guilhermenascimento’s reply :)
– gmsantos