1
在角邊,我試圖做類似下面的GET HTTP請求:如何從PHP中的AngularJS 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"]);
但我不知道如何從它PARAMS(指數= 1)在PHP。我試圖做它作爲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;
?>
所以,我在如何正在讀PARAMS因爲我們沒有把它傳遞給PHP作爲$數據混淆?
我試圖做到這一點,它說索引是undefined – Skorpius 2014-09-20 03:21:25