问题直接调用$http.post()方法时
传值格式是这样的

php接收端接收到的是json格式的,怎么做的跟Ajax post那样传值呢?
分析原因,angular的$http.post()方法默认数据传输格式是json的
  post: {'Content-Type': 'application/json;charset=utf-8'},
      put:  {'Content-Type': 'application/json;charset=utf-8'}
所以要修改传输格式
 
解决方法如下

在angular模块中加入

//修改post方式 form格式传值
angular.module('MyModule', [], function($httpProvider) {//MyModule是你自己的app名称
  // Use x-www-form-urlencoded Content-Type
  $httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8';
  $httpProvider.defaults.headers.put['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8';
 
   
  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
          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;
  }];
});
 
结果如下

 综上所述,问题就解决了。
 

AngularJS 学习笔记值post传值的更多相关文章

  1. AngularJs学习笔记--Forms

    原版地址:http://code.angularjs.org/1.0.2/docs/guide/forms 控件(input.select.textarea)是用户输入数据的一种方式.Form(表单) ...

  2. AngularJs学习笔记--expression

    原版地址:http://code.angularjs.org/1.0.2/docs/guide/expression 表达式(Expressions)是类Javascript的代码片段,通常放置在绑定 ...

  3. AngularJs学习笔记--directive

    原版地址:http://code.angularjs.org/1.0.2/docs/guide/directive Directive是教HTML玩一些新把戏的途径.在DOM编译期间,directiv ...

  4. AngularJs学习笔记--html compiler

    原文再续,书接上回...依旧参考http://code.angularjs.org/1.0.2/docs/guide/compiler 一.总括 Angular的HTML compiler允许开发者自 ...

  5. AngularJs学习笔记--concepts(概念)

    原版地址:http://code.angularjs.org/1.0.2/docs/guide/concepts 继续.. 一.总括 本文主要是angular组件(components)的概览,并说明 ...

  6. AngularJs学习笔记--Using $location

    原版地址:http://code.angularjs.org/1.0.2/docs/guide/dev_guide.services.$location 一.What does it do? $loc ...

  7. AngularJs学习笔记--I18n/L10n

    原版地址:http://code.angularjs.org/1.0.2/docs/guide/i18n 一.I18n and L10n in AngularJS 1. 什么是I18n和L10n? 国 ...

  8. AngularJs学习笔记--Scope

    原版地址:http://code.angularjs.org/1.0.2/docs/guide/scope 一.什么是Scope? scope(http://code.angularjs.org/1. ...

  9. AngularJs学习笔记--Understanding the Model Component

    原版地址:http://docs.angularjs.org/guide/dev_guide.mvc.understanding_model 在angular文档讨论的上下文中,术语“model”可以 ...

随机推荐

  1. MySQL具体解释(5)-----------函数超全总结

    mysql函数大全   对于针对字符串位置的操作.第一个位置被标记为1. ASCII(str) 返回字符串str的最左面字符的ASCII代码值. 假设str是空字符串,返回0.假设str是NULL,返 ...

  2. HDU 3033 分组背包

    给出N个物品.M金钱.W种类 给出N个物品的性质:所属种类,花费.价值 求每一种类物品至少一个的前提下,所能购买到的最大价值 dp[i][k]表示在第i种物品.总花费为k的最大价值 dp[i][k]= ...

  3. log4cpp的初步使用

    (1)下载log4cpp的工程,编译生成lib文件和dll库 下载路径为:http://sourceforge.net/projects/log4cpp/files/latest/download 如 ...

  4. Windows Service的官方描述,抄下来(不写obj就是LocalSystem)

    How to create a Windows service by using Sc.exe Email Print Support for Windows XP has ended Micro ...

  5. 让你的 Qt 桌面程序看上去更加 native(一共六篇)

    <让你的 Qt 桌面程序看上去更加 native>是一个系列文章.在这个系列中,你将会了解到如何让你的 Qt 桌面应用程序看上去更加 native.这里,我假设你已经清楚如何使用 Qt 编 ...

  6. Activity生命周期方法的调用顺序project与測试日志

    以下为測试activity的方法的运行顺序   project与測试资源地址 androidproject AndroidManifest.xml <? xml version="1. ...

  7. [TroubleShootin]The backup set holds a backup of a database other than the existing &#39;xxdb&#39; database.

     One: he backup set holds a backup of a database other than the existing 'xxdb' database Sometime ...

  8. Python 3语法小记(四)字典 dictionary

    字典是Python里面一种无序存储结构,存储的是键值对 key - value.关键字应该为不可变类型,如字符串.整数.包含不可变对象的元组. 字典的创建很简单,用 d = {key1 : value ...

  9. 手动加入PE文件数字签名信息及格式具体解释图之下(历史代码,贴出学习)

    #include <windows.h> HANDLE hWriteFileHandle = NULL ; HANDLE hReadFileHandle = NULL ; HANDLE h ...

  10. ASM丢失disk header导致ORA-15032、ORA-15040、ORA-15042 Diskgroup无法mount

    SQL> select * from v$version; BANNER --------------------------– Oracle Database 11g Enterprise E ...