this is my test ajax in laravel 5 (refer below)
$("#try").click(function(){
var url = $(this).attr("data-link");
$.ajax({
url: "test",
type:"POST",
data: { testdata : 'testdatacontent' },
success:function(data){
alert(data);
},error:function(){
alert("error!!!!");
}
}); //end of ajax
});
and the trigger link
<a href="#" id="try" data-link="{{ url('/test') }}">Try</a>
and my route
Route::post('test', function()
{
return 'Success! ajax in laravel 5';
});
but it gives me error when I run the console in google chrome and it doesnt return the expected response "return 'Success! ajax in laravel 5';"
POST http://juliver.laravel.com/test 500 (Internal Server Error)
whats wrong/problem to my code? anything im missing?
You can add your URLs to VerifyCsrfToken.php middleware. The URLs will be excluded from CSRF verification.
you have to pass the csrf field through ajax please look at the code here
and you also need to write this input field before this
still if you do not understand please enjoy this video https://www.youtube.com/watch?v=ykXL8o0slJA&t=20s
By default Laravel comes with CSRF middleware.
You have 2 options: