现在我有一个由 angular js Controller 管理的 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 中使用该变量。我怎样才能做到这一点。
最佳答案
在您的 Controller 中添加 $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' )
关于javascript - 如何在 $http.post() 之后从 Angular 导航到 php 页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35389593/