我正在使用Angular Js的登录表单.HTML和验证部分工作正常。Http发送不发送数据到角js的另一个页面
问题是当我使用HTTP POST方法将数据发送到我的servicecall PHP页面并希望将其保存到数据库。
我已经
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
我已经通过设置形式的加密类型,以
enctype="application/x-www-form-urlencoded"
为well.But他们没有试图在JS设置这个尝试了所有的办法是工作我不能够通过$ _REQUEST,$ _POST,$ _GET获得任何这些方法的数据。
我也试过使用PHP库函数。
$postdata = file_get_contents("php://input");
但它给我无法处理,因为POST
数据的数量可能是数百一些奇怪的字符串。
所以这里还有其他解决问题的方法。
代码为http
请求
var req = {
method: 'POST',
url: 'servicecall.php',
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
data: {
username: $scope.loginData.username,
password: $scope.loginData.password,
action : 'checkLogin'
} //First way of sending data
//Second way of sending data which is also not working
//data: "{username:"+$scope.loginData.username+",password:"+$scope.loginData.password+",action:checkLogin}"
}
$http(req).then(function(response){
console.log(response);
}, function(response){
alert("Error "+response);
});
在PHP页面我做
print_r($_REQUEST);
print_r($_POST);
但它打印只是空白阵列状array{}
我们可以看到完整的'http http({})'对象。我怀疑在将数据发送到服务器之前如何格式化数据存在问题。 – Ohgodwhy
请提供$ http调用的代码。似乎有一个问题。 –
你可以添加代码snipet –