简体   繁体   中英

PHP $_GET data submitted via AngularJS

I've been searching around quite a bit and can only find $http.post() examples. My problem is:

I submit data via AngularJS with $http.get however when I out the data sent to my PHP file it continuously comes up NULL. Whenever I use $http.post() things work accordingly. What am I doing wrong.

PS - Noob to Angular

ANGULAR

(function ()
    {
      var app = angular.module('app', ['ngRoute']);

      app.config(function($routeProvider){
          $routeProvider
            .when('/players', {
                templateUrl: 'partials/players.html',
                controller: 'PlayersController'
            })
            .otherwise({
                redirectTo: 'index.html'
            });
      });

        app.controller('PlayersController', ['$scope', '$http', function ($scope, $http) 
            {
                $http
                    .get('executer.php', {
                        params: {
                            league: "NFL",
                            team: "Ravens"
                        }
                    })
                    .success(function(response)
                    {
                        console.log(response);
                    })
                    .error(function()
                    {
                        console.log("error"); 
                    });
            }
        ]);
    })
();

PHP

<?php
require_once($_SERVER['DOCUMENT_ROOT'].'/php/Class/Database.php');
require_once($_SERVER['DOCUMENT_ROOT'].'/php/Class/Search.php');

$data = json_decode(file_get_contents("php://input"));
echo json_encode($data); die();

Taking a wild guess, but assuming it has to do with "php://input", however I have no clue what that is actually doing - merely copy/pasted from another Stack post.

Thanks

对于get请求,您将使用超级全局$_GET来检索发送的数据

echo json_encode($_GET); die();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM