mardi 15 mars 2016

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}','AdminController@getInsert');
Route::post('fornitori/create','SupplierController@postCreate');});

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



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire