![](/img/trans.png)
[英]How to catch echoed value from PHP file called from http.post (Angular2)?
[英]how to navigate from angular to php page after $http.post()
现在,我有一个由角度js控制器管理的php页面“ userreq.php”。单击按钮,我正在调用一个函数,该函数将数据发布到另一个php页面“ checkout.php”。
$http({
url: "checkout.php",
method: "POST",
data: {
data: variable
}
}).success(function(response) {
console.log(response);
});
这就是我的发布方式。现在,我希望页面在变量发布后导航到checkout.php,以便我可以在checkout.php中使用该变量。 我该如何实现。
在控制器中添加$httpParamSerializerJQLike
并将数据作为查询参数传递。
范例:
var url = 'checkout.php';
var data = { id: 1, name: 'foo' };
$http({
url: url,
method: "POST",
data: data
})
.success(function(response) {
console.log(response);
window.location.href = url + '?' + $httpParamSerializerJQLike(data);
});
然后在您的php中,从$_GET
检索数据:
$field = $_GET[$field];
// Output: array( 'id' => 1, 'name' => 'foo' )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.