问题直接调用$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. poj1887 Testing the CATCHER

    Testing the CATCHER Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 13968   Accepted: 5 ...

  2. 【Android LibGDX游戏引擎开发教程】第06期:图形图像的绘制(下)图片整合工具的使用

    在上一篇文章中,我们提到了图片必须是2的n次方的问题.但是随着Libgdx的不断完善和发展,使用一些工具就 可以很好的解决了这样一个问题,但是它的功能又不仅仅只限于此,那么下面就来让我们看看Textu ...

  3. http 连接复用

    定义 Http/1.0每次请求都需要建立新的TCP连接,连接不能复用.Http/1.1新的请求可以在上次建立的tcp连接之上发送,连接可以复用. 优点 减少重复进行tcp三次握手的开销,提高效率.注意 ...

  4. 编译安装MongoDB C++ Driver (win8.1 vs2013)

    在C++中调用mongodb的库函数需要安装mongodb的c++driver,需要自己编译,(自己搞了一天半 =_=''' ) 官网Build MongoDB From Source 说To bui ...

  5. DNS与网站优化

    点就出现了这样的问题,导致了几小时的访问失败,所以选择优秀的DNS服务器势必关系网站发展的生死存亡.本文做以下分析.     选择良好的DNS服务器要从选择域名注册商说起,在注册域名时多数人看中的仅仅 ...

  6. JAVA_2Lesson

    package test; public class abc { public static void main(String[] arg) { int[][] xx=new int[3][]; xx ...

  7. HDU 4336 Card Collector(动态规划-概率DP)

    Card Collector Problem Description In your childhood, do you crazy for collecting the beautiful card ...

  8. 谁是Docker的开发人员

    由CHRIS DAWSON发表在thenewstack/DATA RESEARCH qianhen123/CHB译 我们分析了Docker的容器库并提出两个问题: 1.Docker的贡献者们感兴趣的其 ...

  9. matlab三维画图

    matlab三维画图主要有三个命令:plot3命令.mesh命令和surf命令. plot3 plot3是三维画图的基本函数,绘制的是最为主要的3D曲线图,最主要的调用格式是: plot3(X,Y,Z ...

  10. 用户界面线程AfxBeginThread的使用

    用户界面线程在运行时会有一个窗口界面和与其相对应的窗口函数,所以它可以通过响应消息来和用户进行交互. AfxBeginThread 函数原型如下: CWinThread *AfxBeginThread ...