duanlu6114
duanlu6114
2016-08-25 16:10

如何从http.post(Angular2)调用的PHP文件中捕获回显值?

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

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • duanfang7270 duanfang7270 5年前

    Solved it. Needed to use

    res.text()
    
    点赞 评论 复制链接分享

为你推荐