2015-12-14 58 views
4

我一直在寻找相当多的东西,只能找到$ http.post()的例子。我的问题是:

我通过$ http.get通过AngularJS提交数据,但是当我输出发送到我的PHP文件的数据时,它会连续出现NULL。每当我使用$ http.post()的东西相应地工作。我究竟做错了什么。

PS - 入门到角

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(); 

瞎猜,但假设它与“PHP做://输入“,但我不知道实际上在做什么 - 仅仅从另一个Stack帖子复制/粘贴。

感谢

回答

2

对您想要使用超级全球$_GET检索数据的GET请求发送

echo json_encode($_GET); die(); 
+0

你是正确的。我不敢相信自己做得比原本要复杂得多。对于有问题的任何人。谢谢大声笑现在感觉很蠢:)当定时器用完时,我们会接受答案。谢谢 '$ data = $ _GET;回声json_encode($ data ['league']); echo json_encode($ data ['team']); die();' – Pmike86