解决方案:

  1. 配置$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'  
       }  
    
    });  

     

  2. 或者在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);  
    })  

     

相关文章:

  • 2022-12-23
  • 2021-07-22
  • 2022-12-23
  • 2021-05-30
  • 2022-02-13
  • 2021-07-20
  • 2021-10-02
  • 2022-01-16
猜你喜欢
  • 2022-12-23
  • 2021-06-29
  • 2021-10-09
  • 2022-12-23
  • 2021-11-16
  • 2021-07-27
  • 2021-11-06
相关资源
相似解决方案