$http post传值的问题
var app = angular.module("myApp", [], function ($httpProvider) {
$httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8';
/**
* The workhorse; converts an object to x-www-form-urlencoded serialization.
* @param {Object} obj
* @return {String}
*/
var param = function (obj) {
var query = '', name, value, fullSubName, subName, subValue, innerObj, i;
for (name in obj) {
value = obj[name];
if (value instanceof Array) {
for (i = 0; i < value.length; ++i) {
subValue = value[i];
fullSubName = name + '[' + i + ']';
innerObj = {};
innerObj[fullSubName] = subValue;
query += param(innerObj) + '&';
}
}
else if (value instanceof Object) {
for (subName in value) {
subValue = value[subName];
fullSubName = name + '[' + subName + ']';
innerObj = {};
innerObj[fullSubName] = subValue;
query += param(innerObj) + '&';
}
}
else if (value !== undefined && value !== null)
query += encodeURIComponent(name) + '=' + encodeURIComponent(value) + '&';
}
return query.length ? query.substr(0, query.length - 1) : query;
};
// Override $http service's default transformRequest
$httpProvider.defaults.transformRequest = [function (data) {
return angular.isObject(data) && String(data) !== '[object File]' ? param(data) : data;
} ];
});
app.controller("addController", ["$scope", "$http", function ($scope, $http) {
$scope.save = function () {
if ($scope.myForm.$valid) {
var data = { "name": $scope.txtname, "address": $scope.txtaddress, "phone": $scope.txtphone, "zipcode": $scope.txtzipcode, "isdefault": $scope.cbxisdefault };
$http.post("AddUserAddress", data).success(function (result) {
alert(result);
});
}
}
} ]);
只有配置了$http的默认文档类型才能再后台用Request来获取提交的参数
Content-Type
随机推荐
- JAVA程序优化之字符串优化处理
字符串是软件开发中最为重要的对象之一.通常,字符串对象或其等价对象(如char数组),在内存中总是占据了最大的空间块.因此如何高效地处理字符串,必将是提高系统整体性能的关键所在. 1.String对象 ...
- Ubuntu12.04 下安装Chrome浏览器
第一步 下载. 32位:https://dl.google.com/linux/direct/google-chrome-stable_current_i386.deb 64位:https://dl. ...
- java中Runnable接口含义
Java中实现多线程有两种途径:继承Thread类或者实现Runnable接口. Runnable接口非常简单,就定义了一个方法run(),继承Runnable并实现这个 方法就可以实现多线程了,但是 ...
- jmap命令结合mat插件分析内存泄露--OQL
http://smallnetvisitor.iteye.com/blog/1826434 User.java package gc; import java.util.ArrayList; impo ...
- php preg_match 和preg_match_all
$h3=trim('[我要变强][主流程]整体功能测试点');$matches=array();preg_match_all('/[(.+?)]/', $h3,$matches); print_r($ ...
- BZOJ3390: [Usaco2004 Dec]Bad Cowtractors牛的报复
3390: [Usaco2004 Dec]Bad Cowtractors牛的报复 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 43 Solved: ...
- Delphi 在使用exports中的方法 带参数的用法
最近项目中,需要在一个bpl中调用另一个bpl中的单元的方法, 方法如下: 在被调用的单元中定义: procedure Inner_Ex(VoucherType: TVoucherType); exp ...
- HDU_2050——折线分割平面问题,递推
Problem Description 我们看到过很多直线分割平面的题目,今天的这个题目稍微有些变化,我们要求的是n条折线分割平面的最大数目.比如,一条折线可以将平面分成两部分,两条折线最多可以将平面 ...
- 解耦——Hybrid H5跨平台性思考
跨平台,是HTML5最重要的能力之一.而Hybrid H5因强依赖于具体App,往往不具有跨平台性.这时,将强依赖关系解耦,即可恢复HTML5的跨平台能力.近期我负责手Q红包打赏项目的前端开发,因项目 ...
- HDU 5505 - BestCoder Round #60 - GT and numbers
题目链接 : http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=641&pid=1002 思路 : N有若 ...