[英]How can I stop Angular $http from deserializing the response body?
This: 这个:
$http({method: 'GET', url: '/some/url/returning/json').
success(function(data, status, headers, config) {
console.log(data);
});
shows that Angular is giving me a JavaScript object as the first argument to my success
handler. 显示Angular给我一个JavaScript对象作为
success
处理程序的第一个参数。 Presumably, it is trying to be smart by sniffing the content-type of the response. 大概是通过嗅探响应的内容类型来尝试变得聪明。
This is undesired behavior. 这是不希望的行为。 How do I tell Angular to give me the response body as a string?
如何告诉Angular将响应主体作为字符串给我?
The undesired behavior is caused by Angular's transformResponse
. 不良行为是由Angular的
transformResponse
引起的。 To turn this off, do: 要关闭此功能,请执行以下操作:
$http({method: 'GET', url: '/some/url/returning/json', transformResponse: [] }).
success(function(data, status, headers, config) {
console.log(data);
});
它在文档中提到可以使用responseType
config选项,大概是这样的:
$http({method: 'GET', url: '/some/url/returning/json', responseType: 'text'})...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.