Ad

500 Internal Server Error Also After Checking CSRF Protection

I'm still having problems with submitting a form via AJAX in a Laravel project. I tried following some tutorials about submitting tokens with an AJAX request in Laravel, but I'm still having the error 500 (internal server error)

This is my script

$(document).on('click',"#registra_fornitore",function() {
$.ajax({
    url: '/fornitori/create',
    method: "POST",
    data: {
        'name':$('#nameSF').val(),
        '_token': $('#_tokenSF').val(),
        'nit':$('#nitSF').val(),
    },
    dataType: "json",
    success: function(data){
        alert(data);
    }
});

This is the HTML for the form

<form>
<div class="form-group">
    <label for="nameSF">Nome</label>
    <input type="text" class="form-control" id="nameSF" placeholder="Nome">
</div>
<div class="form-group">
    <label for="nitSF">NIT</label>
    <input type="text" class="form-control" id="nitSF" placeholder="NIT">
</div>
<input type="hidden" id="_tokenSF" value="{{ Session::token() }}">
<button type="button" class="btn btn-default" data-dismiss="modal">Annulla</button>
<button type="button" class="btn btn-primary" id="registra_fornitore">Registra</button></form>

And this is the routes file

Route::group(['middleware' => ['web']], function () {
Route::get('/', function () {
    return view('home');
});

Route::get('insert/{scope}','[email protected]');
Route::post('fornitori/create','[email protected]');});

Any ideas of the problem? I tried also the different approach, writing the token value in a meta tag in the header of my template, and passing it in the ajaxsetup

Ad

Answer

Sorry, I found out the problem was a misspelling error in the storing method in the controller.

Ad
source: stackoverflow.com
Ad