$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
随机推荐
- Spring4.0学习笔记(2) —— 自动装配
Spring IOC 容器可以自动装配Bean,需要做的是在<bean>的autowire属性里指定自动装配的模式 1)byType 根据类型自动装配,若IOC 容器中有多个目标Bean类 ...
- Mysql删除表名中有特殊字符的表
由于公司业务和应用的调整,之前在Mysql中的很多表都不需要了,故需要对数据库进行整理. 刚开始,我在想:不就删除一些表吗?很好解决,写个简单的脚本就可以了.我先看了数据库中有80000多个表,很 ...
- MBProgressHUD的基本使用
MBProgressHUD的基本使用 分类: IOS2012-10-30 11:19 12047人阅读 评论(2) 收藏 举报 和gitHub上的Demo其实差不多,就是小整理了下,当备忘,想做复杂的 ...
- Swift—类的继承-备
Swift中的继承只能发生在类上,不能发生在枚举和结构体上.一个类可以继承另一个类的方法.属性.下标等特征,当一个类继承其他类时,继承类叫子类,被继承类叫父类(或超类).子类继承父类后,可以重写父类的 ...
- ubuntu14.04使用reaver跑pin码
今天刚说过没找到支持ubuntu14.04用reaver跑pin的旧版库文件这就有摸索到方法了... 另外安装系统ubuntu14.04以及一系列破解工具比如aircrack,minidwep等都不在 ...
- android更新SDK时候丢失annotations.jar 导致支持库报错
I am trying to update my Android SDK Tools to 17 rev. and I updated usign SDK Tools but in Propertie ...
- SQLServer备忘
1,创建主键有三种方式,尤其注意联合主键: (1) (2) (3) 2,修改主键的方式 2,创建外键应该也有三种方式:
- BZOJ 2693 jzptab
http://www.lydsy.com/JudgeOnline/problem.php?id=2693 题解: 考虑把lcm转化成gcd那答案就是然后神奇的设:就有:一样可以枚举 的取值,这是O(√ ...
- 在Activity的生命周期中,会被系统回调的方法
onCreate(Bundle savedStatus):创建Activity时被回调.onStart():启动Activity时被回调.onRestart():重新启动Activity时被回调.on ...
- Skipped Rebuild All: Project with VS2008
This Problem is getting me head around it in these days. BUt , i have solve it: Description of Probl ...