-2
我想在http.post()错误后从json文件中获取数据,以显示在json文件中发布的错误消息。 我的代码:离子2:在http.post()中发生错误后,我可以在json文件中获取数据吗?
this.http.post('my-url', postParams, options)
.subscribe(res => {
console.log(res.json());
}, error => {
console.log(error);// Error getting the data
});
在JSON文件错误的时间,错误信息被发送,但我不能得到它。
感谢,但你的代码是一样的我的代码有问题,这只是使用: error.json() –
是@ M.Hajavi,它非常相似,但推荐的方式来获得响应(和错误)的主体是通过使用'map'运算符,而不是调用'json )'方法都在响应和错误对象中。 – sebaferreras
我试过了,但它不起作用 –