Are you clicking on a link to trick reaction and have you prevented the default behaviour?
Oct 13, 2022
6
Level 1
GET Method not supported on route, but I am using POST
I am sending a POST request via AJAX to a route called store_fr. Any time I fire the call I am getting an error that the route does not support the GET method (I am sending the call as post).
Ajax call:
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$.ajax({
type: 'POST',
url: "{{ route('ajax.store_fr') }}",
data: {
id: $('#list').val(),
official_title_fr: $('#official_title_fr').val(),
},
success: function(data) {
$.ajax({
type: 'GET',
url: "{{ route('pdf') }}",
data: {
id: $('#countryList').val(),
},
success: function(data) {
downloadHTML(html_data.success['id'], html_data.success['name'],
'en');
downloadHTML(html_data.success['id'], html_data.success['name'],
'fr');
$('#loading').hide();
Swal.close();
Swal.fire({
icon: 'success',
returnFocus: false,
onAfterClose: () => window.scrollTo(0, 0)
});
},
error: function() {
Swal.close();
Swal.fire({
icon: 'error',
returnFocus: false,
onAfterClose: () => window.scrollTo(0, 0)
});
$('#loading').hide();
}
});
}
});
My routes:
Route::controller(AjaxController::class)->group(function () {
Route::get('/ajaxretrieve', 'index')->name('ajax.retrieve');
Route::post('/ajaxstore', 'store')->name('ajax.store');
Route::post('/ajaxstorefr', 'store_fr')->name('ajax.store_fr');
});
and the body of the error code:
$this->methodNotAllowed($methods, $request->method());
}
/**
* Throw a method not allowed HTTP exception.
*
* @param array $others
* @param string $method
* @return void
*
* @throws \Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
*/
protected function methodNotAllowed(array $others, $method)
{
throw new MethodNotAllowedHttpException(
$others,
sprintf(
'The %s method is not supported for this route. Supported methods: %s.',
$method,
implode(', ', $others)
)
);
}
/**
* Compile the routes for caching.
*
* @return array
*/
Level 104
Please or to participate in this conversation.