【发布时间】:2017-09-26 07:20:27
【问题描述】:
我编写了一个函数来发送一个 http put 请求来更新一些数据,但它说它没有收到任何数据:
updateHuman(human: Human) {
const url = `${this.url}/${human.id}`;
const data = JSON.stringify(human);
return this.http.put(url, data).map(
response => response.json().data as Human,
error => console.log(error)
);
}
在我将功能更改为以下内容后,它正在工作:
updateHuman(human: Human) {
const url = `${this.url}/${human.id}`;
const data = JSON.stringify(human);
return this.http.put(url, data).map(() => human);
}
谁能解释一下,为什么第一个功能不起作用,而第二个功能起作用?
【问题讨论】:
-
也许这有帮助:如果我输出我的响应,如上所述,不起作用,我得到这个:响应 {_body: null, status: 204, ok: true, statusText: "无内容”,标题:标题,...} 标题:标题 _headers:映射(1){“内容类型”=> 数组(1)} _normalizedNames:映射(1){“内容类型”=>“内容类型"} proto : Object ok : true status : 204 statusText : "No Content" type : null url : "api/human/2" _body : null proto : Body
标签: javascript angular http typescript