Как получить параметры из HTTP-запроса AngularJS GET внутри php?

Со стороны Angular я пытаюсь выполнить HTTP-запрос GET следующим образом:

$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"]);

Но я не уверен, как получить параметры (index = 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;
?>

Итак, я запутался в том, как читаются параметры, так как мы не передаем их в php как $ data?

1

Решение

Используйте объект в качестве параметра вместо строки:

params:  {index:1},

тогда в your.php

print_r($_GET['index']);
1

Другие решения

ты можешь попробовать это

$_GET['index']

params работает так же, как URL после ? когда Method является GET

0