亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

angularJS 發(fā)起$http.post和$http.get請(qǐng)求的實(shí)現(xiàn)方法

 更新時(shí)間:2017年05月18日 17:05:53   作者:xiaoxiang-chen  
本篇文章主要介紹了angularJS 發(fā)起$http.post和$http.get請(qǐng)求的實(shí)現(xiàn)方法,分別介紹了$http.post和$http.get請(qǐng)求的方法,有興趣的可以了解一下

AngularJS發(fā)起$http.post請(qǐng)求

代碼如下:

$http({ 
  method:'post', 
  url:'post.php', 
  data:{name:"aaa",id:1,age:20} 
}).success(function(req){ 
  console.log(req); 
}) 

這時(shí)候你會(huì)發(fā)現(xiàn)收不到返回的數(shù)據(jù),結(jié)果為null,這是因?yàn)橐D(zhuǎn)換成form data。

解決方案:

配置$httpProvider:

var myApp = angular.module('app',[]); 
 myApp.config(function($httpProvider){ 

  $httpProvider.defaults.transformRequest = function(obj){ 
   var str = []; 
   for(var p in obj){ 
    str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p])); 
   } 
   return str.join("&"); 
  } 

  $httpProvider.defaults.headers.post = { 
    'Content-Type': 'application/x-www-form-urlencoded' 
  } 

}); 

或者在post中配置:

$http({ 
  method:'post', 
  url:'post.php', 
  data:{name:"aaa",id:1,age:20}, 
  headers:{'Content-Type': 'application/x-www-form-urlencoded'}, 
  transformRequest: function(obj) { 
   var str = []; 
   for(var p in obj){ 
    str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p])); 
   } 
   return str.join("&"); 
  } 
}).success(function(req){ 
    console.log(req); 
}) 

AngularJS發(fā)起$http.post請(qǐng)求

代碼如下:

  app.controller('sprintCtrl', function($scope, $http) {
      $http.get("http://localhost:8080/aosapp/pt/service?formid=pt_aosapp_service_sprintlist&teamid=1")
      .success(function (response) {console.log($scope.sprintlist=response);});
    });

其實(shí),angularjs 和 jquery js最大的區(qū)別在哪兒那,angularjs是你事先在心中構(gòu)建好真?zhèn)€頁(yè)面,然后用變量或者占位符來(lái)表示數(shù)據(jù),數(shù)據(jù)來(lái)了,直接填充就可以了;而jquery則是動(dòng)態(tài)的修改dom元素,如添加修改dom標(biāo)簽等。設(shè)計(jì)思想不一樣。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論