一、代码如下:
method:'post',url:'post.PHP',data:{name:"aaa",id:1,age:20}
}).success(function(req){
console.log(req);
})
解决方案:
1、
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("&");
2.
method:'post',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);
})
PHP
PHP;">
$rawpostdata = file_get_contents("PHP://input");
$post = json_decode($rawpostdata,true);
//传的数据都在$post中了;
二、 $http请求数据主要会有以下三种方式
1.get请求
2.post请求
3.jsonp