Reputation: 1
I'm trying to make an ajax in laravel and i get this: "The POST method is not supported for this route. Supported methods: GET, HEAD". The problem is that I've done ajax in my project before, only with this i have a problem. Can anyone help?
My route:
Route::get('/admin/clients-data','App\Http\Controllers\ClientsController@gravy');
Route::get('/admin/client-details/{slug}','App\Http\Controllers\ClientsController@clientdetails');
Route::post('/admin/client-details/adddocumentstoclient','App\Http\Controllers\ClientsController@adddocumentstoclient');
My controller:
public function adddocumentstoclient(Request $request){
echo '<pre>';
var_dump('bump');
echo '</pre>';
die();
}
And my js:
$('.tasks input').on('click', function() {
var emptyValue = 0;
$('input:checked').each(function() {
emptyValue += parseInt($(this).val());
});
var documents_brought = [];
var documents = $('.documents_brought input:checked').each(function(){
documents_brought.push($(this).data('documentid'));
});
var client_id = $('.documents_brought').data('clientid');
$.ajax({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
type: "POST",
url: "adddocumentstoclient",
data: {'documents_brought':documents_brought,'client_id': client_id},
success: function (html) {
// returndata = JSON.parse(html);;
// toastr.success(returndata.message, returndata.title);
}
});
$('.progress-bar').css('width', emptyValue + '%').attr('aria-valuenow', emptyValue);
});
Thanks in advance
Upvotes: 0
Views: 1036
Reputation: 2545
Ok the problem is here
Route::get('/admin/client-details/{slug}','App\Http\Controllers\ClientsController@clientdetails');
Route::post('/admin/client-details/adddocumentstoclient','App\Http\Controllers\ClientsController@adddocumentstoclient');
The first route is get
and you accept slug
param so whenever yo hit /admin/client-details/adddocumentstoclient
it will be matched with first route which is get
and you will never reach your second route.
Solution here to add a prefix before slug
in /admin/client-details/{slug}
or to change second route prefix /admin/client-details/
to differentiate between both routes.
Upvotes: 1