angularjs $http.get 和 $http.post 傳遞參數


$http.get請求數據的格式

[js]  view plain  copy
  1. $http.get(URL,{  
  2.     params: {  
  3.         "id":id  
  4.     }  
  5. })  
  6. .success(function(response, status, headers, config){  
  7.       
  8. })  

 

$http.post請求數據的格式

[js]  view plain  copy
  1. $http.post(URL,{  
  2.     "id":id  
  3. })  
  4. .success(function(response, status, headers, config){  
  5.   
  6. })  

 

tips:

get 和 post方法傳遞參數的方式不一樣

 

[java]  view plain  copy
  1. //分享商品 list 列表  
  2. .factory("shareGoodsListService",["$http",function($http){  
  3.     return {  
  4.         //得到所有的收貨地址  
  5.         updateAddress : function(__scope__,addrid){  
  6.   
  7.             //獲取地址的值  
  8.             var Province = $("select[name='Province']").val();  
  9.             var City = $("select[name='City']").val();  
  10.             var Area = $("select[name='Area']").val();  
  11.   
  12.             var formData = {  
  13.                 id:addrid,  
  14.                 name:__scope__.formData.name,  
  15.                 mobile:__scope__.formData.mobile,  
  16.                 province:Province,  
  17.                 city:City,  
  18.                 area:Area,  
  19.                 address:__scope__.formData.address,  
  20.                 zip:__scope__.formData.zip,  
  21.                 submit:"submit"  
  22.             };  
  23.   
  24.             $http.post("{:U('AddressInfo/editAddress')}",formData).success(function(response, status, headers, config){  
  25.                 if(response.status == 1){  
  26.                     alert("修改成功!");  
  27.                 }  
  28.             })  
  29.         },  
  30.         getAddress:function(){  
  31.             //$http.get方法 傳遞參數使用的是 {params:jsonObj}  
  32.             $http.get("{:U('AddressInfo/editAddress')}",{  
  33.                 params: {  
  34.                     "id":id  
  35.                 }  
  36.             })  
  37.             .success(function(response, status, headers, config){  
  38.                 //獲取地址的數據  
  39.                 if(response.status == 1){  
  40.                     __scope__.formData = {  
  41.                         name:response.data.name,  
  42.                         mobile:response.data.mobile,  
  43.                         address:response.data.address,  
  44.                         zip:response.data.zip  
  45.                     };  
  46.                     //默認收貨地址的值  
  47.                     new PCAS("Province","City","Area",response.data.province,response.data.city,response.data.area);  
  48.                 }  
  49.             })  
  50.         }  
  51.   
  52.     }  
  53. }])  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM