您的位置:首页 > 移动开发

AngularJS通过post、put提交application/x-www-form-urlencoded的数据

2016-11-16 10:38 721 查看
默认情况下,AngularJS通过post和put提交的参数是以json形式提交的,
某些情况下需要application/x-www-form-urlencoded形式的数据,就需要在执行http时重写transformRequest。
比如:
$http({
method: 'POST',
url: url,
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
transformRequest: function(obj) {
var str = [];
for(var p in obj)
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
return str.join("&");
},
data: {
username: $scope.userName,
password: $scope.password
}
}).success(function () {});
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐