1. var app = angular.module("myApp", [], function ($httpProvider) {

  2. $httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8';
  3. /**
  4. * The workhorse; converts an object to x-www-form-urlencoded serialization.
  5. * @param {Object} obj
  6. * @return {String}
  7. */
  8. var param = function (obj) {
  9. var query = '', name, value, fullSubName, subName, subValue, innerObj, i;
  10.  
  11. for (name in obj) {
  12. value = obj[name];
  13.  
  14. if (value instanceof Array) {
  15. for (i = 0; i < value.length; ++i) {
  16. subValue = value[i];
  17. fullSubName = name + '[' + i + ']';
  18. innerObj = {};
  19. innerObj[fullSubName] = subValue;
  20. query += param(innerObj) + '&';
  21. }
  22. }
  23. else if (value instanceof Object) {
  24. for (subName in value) {
  25. subValue = value[subName];
  26. fullSubName = name + '[' + subName + ']';
  27. innerObj = {};
  28. innerObj[fullSubName] = subValue;
  29. query += param(innerObj) + '&';
  30. }
  31. }
  32. else if (value !== undefined && value !== null)
  33. query += encodeURIComponent(name) + '=' + encodeURIComponent(value) + '&';
  34. }
  35.  
  36. return query.length ? query.substr(0, query.length - 1) : query;
  37. };
  38.  
  39. // Override $http service's default transformRequest
  40. $httpProvider.defaults.transformRequest = [function (data) {
  41. return angular.isObject(data) && String(data) !== '[object File]' ? param(data) : data;
  42. } ];
  43.  
  44. });
  1. app.controller("addController", ["$scope", "$http", function ($scope, $http) {
  2.  
  3. $scope.save = function () {
  4. if ($scope.myForm.$valid) {
  5. var data = { "name": $scope.txtname, "address": $scope.txtaddress, "phone": $scope.txtphone, "zipcode": $scope.txtzipcode, "isdefault": $scope.cbxisdefault };
  6. $http.post("AddUserAddress", data).success(function (result) {
  7. alert(result);
  8. });
  9. }
  10. }
  11. } ]);

只有配置了$http的默认文档类型才能再后台用Request来获取提交的参数

  1. Content-Type

随机推荐

  1. Spring4.0学习笔记(2) —— 自动装配

    Spring IOC 容器可以自动装配Bean,需要做的是在<bean>的autowire属性里指定自动装配的模式 1)byType 根据类型自动装配,若IOC 容器中有多个目标Bean类 ...

  2. Mysql删除表名中有特殊字符的表

    由于公司业务和应用的调整,之前在Mysql中的很多表都不需要了,故需要对数据库进行整理.   刚开始,我在想:不就删除一些表吗?很好解决,写个简单的脚本就可以了.我先看了数据库中有80000多个表,很 ...

  3. MBProgressHUD的基本使用

    MBProgressHUD的基本使用 分类: IOS2012-10-30 11:19 12047人阅读 评论(2) 收藏 举报 和gitHub上的Demo其实差不多,就是小整理了下,当备忘,想做复杂的 ...

  4. Swift—类的继承-备

    Swift中的继承只能发生在类上,不能发生在枚举和结构体上.一个类可以继承另一个类的方法.属性.下标等特征,当一个类继承其他类时,继承类叫子类,被继承类叫父类(或超类).子类继承父类后,可以重写父类的 ...

  5. ubuntu14.04使用reaver跑pin码

    今天刚说过没找到支持ubuntu14.04用reaver跑pin的旧版库文件这就有摸索到方法了... 另外安装系统ubuntu14.04以及一系列破解工具比如aircrack,minidwep等都不在 ...

  6. 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 ...

  7. SQLServer备忘

        1,创建主键有三种方式,尤其注意联合主键: (1) (2) (3)   2,修改主键的方式       2,创建外键应该也有三种方式:

  8. BZOJ 2693 jzptab

    http://www.lydsy.com/JudgeOnline/problem.php?id=2693 题解: 考虑把lcm转化成gcd那答案就是然后神奇的设:就有:一样可以枚举 的取值,这是O(√ ...

  9. 在Activity的生命周期中,会被系统回调的方法

    onCreate(Bundle savedStatus):创建Activity时被回调.onStart():启动Activity时被回调.onRestart():重新启动Activity时被回调.on ...

  10. 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 ...