我最近设法得到一个简单的ajax帖子,但无法获得控制器中的任何数据:
Ajax:
function verify(event) {
var title = event.title;
var start = event.start.format("h:m");
$.ajax({
url: "/admin/timetable/verify",
headers: {
'X-CSRF-TOKEN': $('#crsf').val()
},
type: "post",
contentType: "application/json; charset=utf-8",
data: {type : 'hi',titles : title},
dataType: "json",
success: function(response){
if (response['state']==='0')
toastr.error('Are you the 6 fingered man?'+response['msg']);
if (response['state']==='1')
toastr.info('Are you the 6 fingered man?');
},
error : function(e){
console.log(e.responseText);
}
});
}
控制器:
$d = Request::all();
dd($d);
return response()->json(['state'=>'0','msg'=>$d['titles']],200);
我尝试了全部请求,输入全部,输入:: json() - >全部()..没有任何工作总是null或空数组[]!我只是想读取从ajax表单发送的数据!
3 回答
我最近面对这个 . 问题(我不知道为什么)是关于Get和POST的 .
只需将路由转换为GET,将ajax类型设置为GET,然后尝试使用非常简单的
Input::all
.这是我测试的代码,它的工作原理
}
并在我的路线关闭
在php控制器中你需要有这样的东西 .
你可以通过
$request->input('type')
和$request->input('titles')
访问type
和title
另外尝试使用get方法并在
yourproject/routes/web.phpweb.php