0

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????

lt.price
  • 79
  • 1
  • 7
  • You have to be more specific about the error, not working does not help us identify the problem. Please add the error – adot May 11 '18 at 07:59
  • nothing to show any error. only can't see my name.(posted data) – lt.price May 11 '18 at 08:06
  • you are making a `post`, what's the response payload when you examine `network` on developer tools? – adot May 11 '18 at 08:07
  • @Reshan He didn't mention errors. Can you put what you can observe in the developer tools network tab? May be 400 HttpStatus Code etc. Btw why don't you use HttpClientModule? – Rukshan Dangalla May 11 '18 at 08:31

0 Answers0