thinkphp5.1 $this->request->isPost()问题

$this->request->isPost() 在接收空数据的
使用$.post(target, query).success(function(data) {
会报下面报错

Deprecated: Automatically populating $HTTP_RAW_POST_DATA is deprecated and will be removed in a future version. To avoid this warning set 'always_populate_raw_post_data' to '-1' in php.ini and use the php://input stream instead. in Unknown on line 0
阅读 7.7k
2 个回答

解决方案
前端页面发起$.post时传递到后端的data参数肯定没给值

$.ajax({
    type:'POST',
    url:'url地址',
    data:{a:'123'},// 这里要给值,可以随便填,不填就会报错
})

$this->request->isPost();
request()->isPost();
以上两个都是检测是否为POST请求

接受参数用:

input(); //获得全部参数 返回数组
input('post.','') //获取全部post参数 默认值为'';
input('post.name','') //获取post参数里面的name值 默认为空

还可以使用:

$this->request->post('name','');
request()->post('name','');
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进