角代碼:如何將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://stackoverflow.com/questions/41154319/how-to-post-json-object-with-http-post-angular-2-php-server-side/41155043#41155043 –
我試過答案,但沒有得到什麼錯誤在我的代碼,即時通訊仍然在codeIgniter一側,應該我需要配置我的codeIgniter的東西嗎?由於角度響應很好。 – James
你也可以發佈「userObj」。 –