aWe*_*per 1 javascript angularjs angular-resource
以下代码将表单数据发布为json而不是键值对.
服务
$resource(apiPath, {
Id: '@Id',
apt_id: user_info.apt_id,
mauth_token: user_info.mauth_token,
mauth_account_id: user_info.mauth_acnt_id,
rest: 1,
}, {
save:{
method:'POST',
headers : {'Content-Type': 'application/x-www-form-urlencoded'}
}
});
Run Code Online (Sandbox Code Playgroud)
调节器
.controller('BroadcastSmsSendCtrl', function($scope, $ionicLoading, $ionicActionSheet, $state, $timeout, $location, BroadcastSmsSvcs, GetUserCountHttpSvcs) {
$scope.entry = new BroadcastSmsSvcs();
$scope.doSubmit = function() {
BroadcastSmsSvcs.save({}, $scope.entry);
};
});
Run Code Online (Sandbox Code Playgroud)

Cod*_*ist 12
AngularJs提供了一种服务,可以像序列化对象一样转换为jQuery.
而不是json序列化: {"id": 1, "name": "whatever"}
它成为了: id=1&name=whatever
所以你可以做到:
save:{
method: "POST",
headers : {"Content-Type": "application/x-www-form-urlencoded"},
transformRequest: function(data) {
return $httpParamSerializerJQLike(data);
}
}
Run Code Online (Sandbox Code Playgroud)
注意:在您的服务中,您必须注入$httpParamSerializerJQLike服务
| 归档时间: |
|
| 查看次数: |
5315 次 |
| 最近记录: |