如何将Angular 2 http.post请求发送给codeigniter?
问题描述:
角代码:如何将Angular 2 http.post请求发送给codeigniter?
sendData(obj){
const userObj = JSON.stringify(obj); console.log(userObj);
let headers = new Headers();
headers.append("Content Type","application/json");
return this.http.post('http://localhost/codeigniter/index.php/ngGet_Controller/posted', userObj, headers);
}
CoeIgniter(控制器)代码:
public function posted(){
$postdata = file_get_contents("php://input");
var_dump(json_decode($postdata));
print_r($this->input->post());
}
试试这个答案https://*.com/questions/41154319/how-to-post-json-object-with-http-post-angular-2-php-server-side/41155043#41155043 –
我试过答案,但没有得到什么错误在我的代码,即时通讯仍然在codeIgniter一侧,应该我需要配置我的codeIgniter的东西吗?由于角度响应很好。 – James
你也可以发布“userObj”。 –