0
我使用http.get从数据库中获取数据。我发送的参数与URL一起。但参数不能从该网址访问。如何检索使用http.get发送的参数
这里是我的Angularjs控制器代码:
app.controller('ListCtrl', ['$scope', '$http', '$location', '$window', function($scope,$http,$location,$window){
$scope.data = {};
$scope.getdata = function(){
$scope.datas = [];
$http({
url: "http://localhost/angular/data.php",
method: "GET",
params: {'place':$scope.data.place,'pincode':$scope.data.pincode}
})
.success(function(data,status,headers,config){
$scope.datas=data;
console.log($scope.datas);
$scope.navig('/show.html');
})
.error(function(){
alert("failed");
});
};
$scope.navig = function(url){
$window.location.href = url;
};
}])
这里是我的data.php文件
<?php
header("Access-Control-Allow-Origin: *");
$postdata = file_get_contents("php://input");
$data= json_decode($postdata);
$place = mysql_real_escape_string($data->place);
$pincode = mysql_real_escape_string($data->pincode);
//$place = $_GET[$data->place];
if ($place){
$connection = mysqli_connect("localhost","root","","building") or die("Error " . mysqli_error($connection));
$sql = "SELECT * from details ";
$result = mysqli_query($connection, $sql) or die("Error in Selecting " . mysqli_error($connection));
$detail = array();
while($row =mysqli_fetch_assoc($result))
{
$detail[] = $row;
}
echo json_encode($detail);
mysqli_close($connection);
}
else {
echo "no place entered";
}
?>
它输出的,即使我进入的地方 “进入不到位”。
这是检索数据的正确方法吗?
我通过任一地点或pincode,而不是两个。会导致任何问题?
请大家帮忙。
您正在使用GET在你的AJAX调用,但期望通过'file_get_contents(“php:// input”)''在PHP中进行POST。选择其中之一。 – mitkosoft
我是一个新手,我不知道如何获得该参数。我应该用什么来代替file_get_contents(“php:// input”)。我必须使用GET而不是POST。 – Abdulla
要访问GET参数,请使用$ _GET全局数组而不是php:// input,它是来自请求主体的输入。 –