Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么我能';我得不到$this->;JSON.stringify post数据中的post()值_Json_Rest_Codeigniter_Post_Stringify - Fatal编程技术网

为什么我能';我得不到$this->;JSON.stringify post数据中的post()值

为什么我能';我得不到$this->;JSON.stringify post数据中的post()值,json,rest,codeigniter,post,stringify,Json,Rest,Codeigniter,Post,Stringify,我在CodeIgniter框架中创建了一个简单的RESTfulWeb服务,作为我学生的示例项目 我的一个API函数出现问题,如下所述: public function newmember\u post() { $data=json_decode($this->post()[0],true);//来宾_model->insertMember($data); 如果($ok){ $this->response(['status'=>'OK','member\u ID'=>$OK],200); }否则{

我在CodeIgniter框架中创建了一个简单的RESTfulWeb服务,作为我学生的示例项目

我的一个API函数出现问题,如下所述:

public function newmember\u post()
{
$data=json_decode($this->post()[0],true);//来宾_model->insertMember($data);
如果($ok){
$this->response(['status'=>'OK','member\u ID'=>$OK],200);
}否则{
$this->response(['status'=>'Failed'],500);
}
}
当我尝试获取POST数据项时,如

$nama=$this->post('nama));
$alamat=$this->post('alamat');
...
我得到了所有数据项的
null

当我尝试
var\u dump($this->post())
时,我得到了以下结果:

array(1) {
  [0]=>
  string(139) "{"nama":"Devi Chung","alamat":"Jl. Baji Ateka 20","kota":"Makassar","negara":"ID","kodepos":"90131","telepon":"871555","hp":"081234567890"}"
}

// it's a fake identity, no problem
POST数据变成一个数组,因此,我获取POST数据的解决方案如下

$data = json_decode($this->post()[0], true);
我的工作有什么问题,所以我无法使用
$this->POST()以正常方式获取POST数据


在前端,我使用JavaScript Promise来完成数据发布的API请求

const endpoint\u url='1〕http://my.services.web/api';
函数newMemberSave(){
var新成员={
“nama”:document.getElementById(“nama”).value,
“alamat”:document.getElementById(“alamat”).value,
“kota”:document.getElementById(“kota”).value,
“negara”:document.getElementById(“negara”).value,
“kodepos”:document.getElementById(“kodepos”).value,
“telepon”:document.getElementById(“telepon”).value,
“hp”:document.getElementById(“手机”).value
}
获取(端点url+“/guests/newmember”{
方法:“POST”,
body:JSON.stringify(new_member)//您需要在两者之间写入“input”,请尝试以下操作

    $nama = $this->input->post('nama);
    $alamat = $this->input->post('alamat');
你需要在中间写“输入”,试试下面的

    $nama = $this->input->post('nama);
    $alamat = $this->input->post('alamat');

对于
ciu控制器
没错,我们使用
$this->input->post()
$this->input->get()
,但是对于
REST\u控制器
我们只使用
$this->post()
$this->get()。
我也尝试过,得到了
null
post数据$this->input->post()有什么问题或者$\u POST?对于
CI\u控制器
是的,我们使用
$this->input->POST()
或者
$this->input->get()
,但是对于
REST\u控制器
我们只使用
$this->POST()
或者
$this->get()
。我也尝试过,得到了
null
POST数据,$this->input->POST()或者$\u POST有什么问题?