【发布时间】:2014-09-20 03:03:05
【问题描述】:
在 Angular 方面,我正在尝试执行如下所示的 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.ini 中从中检索参数(索引 = 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?
【问题讨论】: