我在laravel 5.8中的ajax请求中遇到问题
问题
POST http://dailyshop.test/ajaxRequest 419(未知状态)
路线
Route::get('ajaxRequest', 'FrontEndController@ajaxRequest');
Ajax代码
$(document).ready(function() {
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$('#add-to-cart').click( function(e) {
e.preventDefault();
var product_id = $(this).data('id');
var url = "{{ route('addToCart') }}";
$.ajax({
type:'POST',
url:'/ajaxRequest',
data:{product_id:product_id},
success:function(data){
alert(data.success);
}
});
});
});
功能
public function ajaxRequest() {
dd('Yes! it working !');
return view('ajaxRequest');
}