我有两个嵌套的HTTP请求。第一个GET转到leadsData.php
以获取JSON文件。第二个将JSON数据发布到leads.php
以呈现页面。目标是显示leads.php
的回复。我不相信我的第二个请求(POST)由于某种原因正在发送数据,因为当打印$scope.content
时,它不会带回数据。
想与大家分享,看看是否有一些基本的东西我可能会忘记。
目标是成功发送$scope.haha
并打印$scope.content
。
var app = angular.module('myApp', ['ngSanitize']);
app.controller('myController', function($scope, $http, $filter, $window) {
//Load Prospective Students
$scope.LoadProspectiveStudents = function() {
//first HTTP Call
$http.get("leadsData.php").
then(function(response) {
//gets the data ready and stores into haha
$scope.haha = response.data;
//second HTTP Call and stores into content
$http.post("leads.php", $scope.haha)
.then(function(response) {
$scope.content = response.data;
})
},
function(response) {
$scope.myData = "Uh oh! Something went wrong";
});
$scope.sortBy = function(x) {
$scope.myData = $filter('orderBy')($scope.myData, x);
}
}
});