从Angular $http POST传递数据数组
发布时间:2020-12-17 08:10:01 所属栏目:安全 来源:网络整理
导读:我需要通过Nancy框架将一系列的对象从我的Angular应用程序传递给.Net Web服务。 我试过这个: function TestCtrl($scope,$http){ $scope.postTest = function(){ var data = [obj1,obj2,obj3]; $http({ url: 'myURL',method: "POST",data: data,headers: { '
我需要通过Nancy框架将一系列的对象从我的Angular应用程序传递给.Net Web服务。
我试过这个: function TestCtrl($scope,$http){ $scope.postTest = function(){ var data = [obj1,obj2,obj3]; $http({ url: 'myURL',method: "POST",data: data,headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' } }).success(function(data){ alert("done"); }); } } 但服务器发送500内部服务器错误。 有人能帮我吗?
根据
this post,你是对的,这是关于序列化。
Angular doesn’t automatic serialize the data for you,您需要在发送之前分析数据:
... $http({ url: 'myURL',data: $.param(data),headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' } })... 如果您不使用jQuery,则需要滚动自己的$ .parse。有一个snippet here或者你可以adapt jQuery implementation。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |