角$资源POST产生无效的JSON体在Internet Explorer 10 [英] angular $resource POST produces an invalid JSON body in Internet Explorer 10
问题描述
以下code运行时,将没有身体POST请求(空体)
在IE 10,在Chrome和Firefox,它的行为正确,
angular.module('测试',['ngResource','ngRoute'])。
配置([功能(){}])angular.module(测试)。
控制器('C1',['$范围,$ HTTP,$资源',函数($范围,$ HTTP,$资源){ $ scope.zaza =波波 VAR Supplyers = $资源(API / supplyer',空,
{获取:{方法:POST,IsArray的:真正}}
) 变种的id = [1,2,3] Supplyers.fetch(
{IDS:IDS},
功能(供应商){
的console.log(>>>中+供货商)
},
功能(错误){
的console.log(!!!+ ERR)
}
) }])
角的文档提供了有关比9年长的IE版本信息:
http://docs.angularjs.org/guide/ie
但没有提到与即10个问题...
角的版本是:
<脚本SRC =https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0-rc.2/angular.min.js类型= 文/ JavaScript的>< / SCRIPT>
<脚本SRC =https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0-rc.2/angular-resource.min.js类型=文/ JavaScript的>< /脚本>
<脚本SRC =https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0-rc.2/angular-route.min.js类型=文/ JavaScript的>< /脚本>
=======更新
我测试了code中的IE9模式和也IE8模式和
惊喜地和足够的,他们都工作,
所以这个问题在IE中10只存在...
=======更新
我包括HTML,注意角度版本的变化(1.0.8)
它也进行同样的操作(后有空的身体...)
<!DOCTYPE HTML>
< HTML和GT;
< HEAD>
<标题>< /标题> <! - [如果LTE IE 8] GT;
<脚本的src =/资产/ JavaScript的/ lib目录/ json3.min.js>< / SCRIPT>
百分比抑制率ENDIF] - GT!;
<脚本SRC =https://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.min.js类型=文/ JavaScript的>< / SCRIPT>
<脚本SRC =https://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular-resource.js类型=文/ JavaScript的>< / SCRIPT>
&所述;! - https://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.min.js
https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0-rc.2
- > <脚本的src =/资产/ Java脚本/ test.js类型=文/ JavaScript的>< / SCRIPT>
< /头>
<机身NG-应用=测试的xmlns:NG =http://angularjs.orgID =NG-应用> < DIV NG控制器=C1> < H1> {{扎扎}}< / H1> < / DIV>
< /身体GT;
< / HTML>
注:与$ http.post有同样的问题,一个帖子:
$ http.post(API / supplyer',{IDS:IDS})。成功(功能(RES){
的console.log(<<+ RES)
})错误(功能(RES){
的console.log(!!+ RES)
})
我打的是同样的问题,因为你。在我的情况下,使用angular.toJson()产生一个有效的机构。
The following code sends a POST request without a body (an empty body) when running in IE 10, in Chrome and Firefox, it behaves correctly,
angular.module('test', ['ngResource', 'ngRoute']).
config([function() {}])
angular.module('test').
controller('c1', ['$scope', '$http', '$resource', function($scope, $http, $resource) {
$scope.zaza = "popo"
var Supplyers = $resource('api/supplyer', null,
{fetch: { method: 'POST', isArray: true}}
)
var ids = [1,2,3]
Supplyers.fetch(
{ids: ids},
function(suppliers) {
console.log(">>>" + suppliers)
},
function(err) {
console.log("!!!" + err)
}
)
}])
Angular's documentation gives info about IE versions older than 9 :
http://docs.angularjs.org/guide/ie
but does not mention issues with ie 10...
Version of angular is :
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0-rc.2/angular.min.js" type="text/javascript"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0-rc.2/angular-resource.min.js" type="text/javascript"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0-rc.2/angular-route.min.js" type="text/javascript"></script>
======= update
I tested the code in "IE9 mode" and also in "IE8 mode" and and surprizingly enough, they both work, so the problem exists only in IE 10...
======= update
I included the html, note the change in angular version (1.0.8) it also behaves the same way (post has empty body ...)
<!DOCTYPE html>
<html>
<head>
<title></title>
<!--[if lte IE 8]>
<script src="/assets/javascripts/lib/json3.min.js"></script>
<![endif]-->
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.min.js" type="text/javascript"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular-resource.js" type="text/javascript"></script>
<!-- https://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.min.js
https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0-rc.2
-->
<script src="/assets/javascripts/test.js" type="text/javascript"></script>
</head>
<body ng-app="test" xmlns:ng="http://angularjs.org" id="ng-app">
<div ng-controller="c1">
<h1>{{zaza}}</h1>
</div>
</body>
</html>
Note: a post with $http.post has the same problems :
$http.post('api/supplyer', {ids: ids}).success(function(res){
console.log("<<" + res)
}).error(function(res){
console.log("!!"+ res)
})
I hit the same problem as you . In my case, using angular.toJson() produced a valid body.
这篇关于角$资源POST产生无效的JSON体在Internet Explorer 10的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!