我的Angular JS HTTP请求调用出了什么问题?

时间:2018-05-01 06:18:27

标签: angularjs ajax http post request

我有两个嵌套的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);
    }
  }



});

0 个答案:

没有答案