【发布时间】:2016-02-06 00:43:22
【问题描述】:
我正在使用$http 方法从angularjs 控制器将一些数据发布到php 页面,如下所示。
$scope.login = function(){
var data = {
'username' : $scope.username,
'password' : $scope.password
};
$http.post('login.php', data).success(function(response){
console.log(response);
});
};
我知道我可以使用 php 检索这些数据:
$postdata = json_decode(file_get_contents('php://input'), true);
但我想知道angularjs 中是否有更好的方法,所以我可以使用php 中的简单$_POST 来检索数据。
在jQuery 中,我们可以简单地使用$.post,而php 在$_POST 中可用。为什么angularjs 没那么简单。
当我们在angularjs 中执行$http post 请求时,有什么方法可以填充php 的$_POST。请帮忙。
【问题讨论】:
-
这在服务中吗??
-
我检查了你提到的帖子。但那篇文章没有解释如何填充
$_POST -
@abdulla 这是一个简单的控制器文件
-
您需要将
$httpProvider.defaults.transformRequest覆盖为将data序列化为标准URL 编码格式而不是JSON 的转换器。阅读一些示例的文档。这只是为您指明正确的方向,如果有人想通过各种方式将其发展为完整的答案,请这样做。