简体   繁体   中英

How to catch echoed value from PHP file called from http.post (Angular2)?

I'm calling a PHP file with the following code:

var link = 'link.php';

var data = JSON.stringify({ email: this.data.email, password: this.data.password});

let headers = new Headers();
headers.append('Content-Type', 'application/json');

this.http.post(link, data, { headers: headers }).subscribe(res => {
  alert(res);
});

I'm echoing a string from the PHP file, but nothing is being stored in res. Is there something I'm missing, or am I completely going about it the wrong way?

Thanks

Solved it. Needed to use

res.text()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM