angular post表單

參數文章:http://angularjs.cn/A0qFangularjs

angularjs中Post使用的是json的交互方法,通常服務器還沒達到這個階段,咱們能夠用回傳統的&參數的方法:json

 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'
   }

});
相關文章
相關標籤/搜索