2015-12-14 61 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