I try to post my data to Server using angular(Angular CLI: 1.7.3) Http.post() method. but it dosn't work. I used php Server.
typescript Function
private url = 'http://localhost/...../post'; // my URL
constructor (private http : Http){ }
addData () {
this.http.post(this.url, {name:'MyName'}) // **
.subscribe(responce => {
console.log(responce);
});
}
PHP Function (use CodeIgniter)
public function post(){
echo 'backend working.. ';
print_r($_POST);
}
I try this (for **)
this.http.post(this.url, JSON.stringify({name:'MyName'}))
& this
this.http.post(this.url, {name:'MyName'}, { headers: new Headers({'Content-Type': 'application/json'}) })
& this
this.http.post(this.url, JSON.stringify({name:'MyName'}), { headers: new Headers({'Content-Type': 'application/json'}) })
& this
this.http.post(this.url, {name:'MyName'}, new RequestOptions({headers : new Headers({'Content-Type': 'application/json'}) }) )
& this
this.http.post(this.url, JSON.stringify({name:'MyName'}), new RequestOptions({headers : new Headers({'Content-Type': 'application/json'}) }) )
but dosn't work anything for me.. :(
console log => backend working.. Array↵(↵)↵
I used CodeIgniter(CodeIgniter-3.1.8) for Backend. How I resolve this problem????