【发布时间】:2015-12-14 23:40:31
【问题描述】:
我已经搜索了很多,只能找到 $http.post() 示例。我的问题是:
我通过 AngularJS 使用 $http.get 提交数据,但是当我将数据发送到我的 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://input”有关,但我不知道它实际上在做什么 - 只是从另一个 Stack 帖子复制/粘贴。
谢谢
【问题讨论】:
标签: javascript php angularjs