我正试图将angularjs控制器中的数据发布到php页面,用于支付网关目的。我可以把所有的内容发布为surl,furl,电子邮件。。。所有必填字段。除此之外,我将一个对象发布为"totalorder",它由嵌套数组和一些其他字段组成。
这是我的控制器文件
$http({
method: "post",
url: window.location.href + "postform.php",
data: {
txnid:$scope.payment.txnid,
amount:$scope.payment.amount=1,
productinfo:$scope.payment.productinfo,
firstname:$scope.payment.firstname,
email:$scope.payment.email,
phone:$scope.payment.phone,
surl:$scope.payment.surl,
furl:$scope.payment.furl,
service_provider:$scope.payment.service_provider,
totalorder:$scope.payment.totalorder,
hash:$scope.payment.hash
/*email: $scope.email,
pass: $scope.password*/
},
headers: { 'Content-Type': 'application/json' }
});
它的发布以及在postform.php页面中显示数据时,在控制台和网页中都显示为[对象对象],但在控制台中无法看到它们的存在。
这是我的postform.php页面
$email=$_POST['email'];
$txnid=$_POST['txnid'];
$firstname=$_POST['firstname'];
$phone=$_POST['phone'];
$amount=$_POST['amount'];
$productinfo=$_POST['productinfo'];
$surl=$_POST['surl'];
$furl=$_POST['furl'];
$totalorder=$_POST['totalorder'];
$totallist=json_decode($totalorder);
echo ("'<script>console.log('$totalorder')</script>'");
甚至我也尝试了不同的方法来获得这些值,比如将数据存储在json_decode、直接访问、foreach概念中,但所有这些都没有用,因为它们只显示给我[对象对象],而不是它们的内部值。
正如我所想的,我的数据发布是正确的。所以,如果有任何提示/其他过程会对我有很大帮助。
请将"$httpParamSerializerJQLike"注入您的控制器/服务/工厂,并使用以下代码,然后就可以开始了。
$http({
method: "post",
url: "/postform.php",
data: $httpParamSerializerJQLike({
txnid:$scope.payment.txnid,
amount:$scope.payment.amount=1,
productinfo:$scope.payment.productinfo,
firstname:$scope.payment.firstname,
email:$scope.payment.email,
phone:$scope.payment.phone,
surl:$scope.payment.surl,
furl:$scope.payment.furl,
service_provider:$scope.payment.service_provider,
totalorder:$scope.payment.totalorder,
hash:$scope.payment.hash
}),
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'X-Requested-With': 'XMLHttpRequest'
}
});