1、如果是form表单的,注意_token字段,form表里可以写 {{ csrf_field() }}
或者
<input type="hidden" name="_token" value="'.csrf_token().'">
2、在页面上添加
<meta name="csrf-token" content="{{ csrf_token() }}">
2.然后在页面的script标签中添加
<script type="text/javascript">
$.ajaxSetup({
headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')}
});
</script>
3、直接使用PHP语言输出【博主有点懒,喜欢使用这种】
$.ajax({
url: "{{ url('/appointment_space') }}" ,
type: 'POST',
data: { _token : '<?php echo csrf_token()?>'},
dataType: 'json',
success: function(data){
console.log(data.status);
},
error: function(xhr, type){
alert('Ajax error!')
}
});