如何指定数据类型:“JSON”在Angular.js $ http.post? [英] How to specify dataType: 'json' in Angular.js $http.post?
问题描述
我想说明数据类型:'json的
在传统的jQuery $ AJAX
。
这可能与Angular.js $ http.post
?
I would like to specify dataType: 'json'
as in conventional jQuery $.ajax
.
Is this possible with Angular.js $http.post
?
推荐答案
从的http:// docs.angularjs.org/api/ng.$http
转化请求和响应 请求和响应可使用变换函数进行变换。默认情况下,角适用这些转变:
Transforming Requests and Responses Both requests and responses can be transformed using transform functions. By default, Angular applies these transformations:
请求转换:
-
如果请求的配置对象的数据属性包含一个对象,其序列化为JSON格式。 响应转换:
if the data property of the request config object contains an object, serialize it into JSON format. Response transformations:
如果检测到XSRF preFIX,剥光它(请参见下面的安全考虑部分)
if XSRF prefix is detected, strip it (see Security Considerations section below)
所以没必要设置是自动完成的数据类型
So no need to set a data type it is done automatically
这篇关于如何指定数据类型:“JSON”在Angular.js $ http.post?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!