I'm using Laravel 5 with ajax post in a popup alert, and it giving me the error "500 Internal Server Error", when I checked firebug, I find that ajax return an error page saying "TokenMismatchException in VerifyCsrfToken.php line 46:"
when I comment App\Http\Middleware\VerifyCsrfToken
, it works fine, but I assume that it's not recommended, I print the _token variable and it's not empty
the ajax post code is:
$('#demo_4').click(function(){
bootbox.prompt("What is your name?", function(result) {
if (result === null) {
alert("Prompt dismissed");
} else {
// alert("Hi <b>"+result+"</b>");
$.ajax({
url: 'test',
type: "post",
data: {'name':result, '_token': $('input[name=_token]').val()},
success: function(data){
alert(data);
}
});
}
});
});
the Route code is:
Route::post('test', 'AccountController@login');
the AccountController code is:
<?php
namespace App\Http\Controllers;
use Input;
use Request;
use App\Http\Controllers;
class AccountController extends Controller
{
public function login()
{
if (Request::ajax()) {
$data = Input::all();
print_r($data);
die;
}
}
}