在角度方面,我尝试执行GET http请求,如下所示:
$scope.getQuestion = function() {
//$http.post($scope.url, { src : $scope.question});
var request = $http({
method: "get",
url: $scope.url,
params: 'index =1',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
});
/* Check whether the HTTP Request is Successfull or not. */
request.success(function (data) {
console.log("GET literally worked");
$scope.loginMessage = data;//angular.fromJson(data);
//console.log($scope.testArray["question2"]);
但我不确定如何在php中从中检索params (index = 1)。我试着以JSON的身份这么做,但似乎不起作用?
PHP端:
<?php
$data = file_get_contents("php://input");
$src = json_decode($data);
//var_dump($_POST);
//$src = $_POST['src'];
//@$toOut = $src->question;
//file_put_contents("output", $toOut);
/*$arr = array (
0 => "does this work?",
"question2" => "i mean i guess?"
);
$jsonString = json_encode($arr);
echo $jsonString;*/
$numArr = $src -> params;
echo $numArr -> index;
?>
所以我对如何读取参数感到困惑,因为我们没有将其作为$data传递给php?
发布于 2015-11-11 02:49:13
使用对象作为参数,而不是字符串:
params: {index:1},
然后在your.php中
print_r($_GET['index']);
发布于 2014-09-20 11:07:43
你可以试试这个
$_GET['index']
当Method
为GET
时,params
与?
后的url工作方式相同
https://stackoverflow.com/questions/25944789
复制相似问题