今天使用$http post功能屏富,返回成功code 200奉瘤,返回數(shù)據(jù)為空泌射,以為是頭部問題晋南。
原因:用angularjs的$http提交的數(shù)據(jù)惠猿,在php服務器端卻無法通過$_REQUEST/$_POST獲取到。
解決:
var json = {testId:1};
var jsonStr = JSON.stringify(json);
var url = 'http:test/test.php';
$http({
method: 'POST',
url: url,
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
transformRequest: function(obj) {
var str = [];
for (var s in obj) {
str.push(encodeURIComponent(s) + "=" + encodeURIComponent(obj[s]));
}
return str.join("&");
},
data: {act:"sixVerificationCode",composerId:8}
}).then(function success(result) {
//數(shù)據(jù)請求成功
console.log("succ:"+JSON.stringify(result));
},function error(err) {
//數(shù)據(jù)請求失敗
console.log(err);
});
}
查看博客:https://blog.csdn.net/gufeilong/article/details/53584967