鍍金池/ 問答/PHP/ thinkphp5.1 $this->request->isP

thinkphp5.1 $this->request->isPost()問題

$this->request->isPost() 在接收空數(shù)據(jù)的
使用$.post(target, query).success(function(data) {
會(huì)報(bào)下面報(bào)錯(cuò)

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
回答
編輯回答
囍槑

$this->request->isPost();
request()->isPost();
以上兩個(gè)都是檢測(cè)是否為POST請(qǐng)求

接受參數(shù)用:

input(); //獲得全部參數(shù) 返回?cái)?shù)組
input('post.','') //獲取全部post參數(shù) 默認(rèn)值為'';
input('post.name','') //獲取post參數(shù)里面的name值 默認(rèn)為空

還可以使用:

$this->request->post('name','');
request()->post('name','');
2017年7月27日 07:20
編輯回答
野橘

解決方案
前端頁面發(fā)起$.post時(shí)傳遞到后端的data參數(shù)肯定沒給值

$.ajax({
    type:'POST',
    url:'url地址',
    data:{a:'123'},// 這里要給值,可以隨便填,不填就會(huì)報(bào)錯(cuò)
})
2017年4月28日 00:29