kyo*_*kyo 2 php ajax jquery laravel laravel-5
我正在尝试发布POST
http://localhost:8888/test
JS
$('.saveBTN').click(function (event) {
$( "form#editForm" ).on( "submit", function( event ) {
event.preventDefault();
var inputs = {};
$("#editForm :input").each(function() {
inputs[$(this).attr("name")] = $(this).val();
});
var $inputs = JSON.stringify(inputs);
$.ajax({
headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
url: '/test',
type: 'POST',
dataType: 'json',
data: $inputs,
success: function (data, textStatus, xhr) {
console.log(data);
},
error: function (xhr, textStatus, errorThrown) {
console.log('PUT error.');
}
});
});
Run Code Online (Sandbox Code Playgroud)
我一直在
500内部服务器错误
我试过补充一下
<meta name="csrf-token" value="{{ csrf_token() }}">
这是我的Ajax
headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
任何关于此的提示将非常感谢!
在表格下方添加此内容.
// This will generate token field which will be token
{{ csrf_field() }}
// Expected Output
<input type="hidden" name="_token" value="ssdfdsfsdfsdfs32r23442">
Run Code Online (Sandbox Code Playgroud)
VerifyCsrfToken.php- middleware包含在Web中间件组中的文件将自动验证token请求输入中的文件是否与会话中存储的令牌匹配.
有关更多信息,请参阅此URL:http: //laravel.com/docs/master/routing#csrf-x-csrf-token
更新 - 2016年12月23日
从laravel开始,您也可以使用以下内容.
<form action="/foo/bar" method="POST">
<input type="hidden" name="_method" value="POST">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
</form>
Run Code Online (Sandbox Code Playgroud)
API参考:https://laravel.com/docs/master/routing#form-method-spoofing
| 归档时间: |
|
| 查看次数: |
1652 次 |
| 最近记录: |