2017-09-25 110 views
1

我有一個簡單的登錄,一旦用戶登錄我已添加回調運行另一個帖子,以便我有權訪問我的系統中使用的後json。成功登錄後運行HTTP POST

我覺得我做的方式是正確的但是我得到錯誤

的GetData沒有定義

這是要做到這一點

的JavaScript的正確方法

$scope.LogIn = function() { 
      $http({ 
       url: "http://www.somesite.co.uk/ccuploader/users/login", 
       method: "POST", 
       data: $.param({'username': $scope.UserName, 'password': $scope.PassWord}), 
       headers: {'Content-Type': 'application/x-www-form-urlencoded'} 
      }).then(function (response) { 
       // success 
       console.log('success'); 
       console.log("then : " + JSON.stringify(response)); 
       GetData(); 
       // location.href = '/cms/index.html'; 
      }, function (response) { // optional 
       // failed 
       console.log('failed'); 
       console.log(JSON.stringify(response)); 
      }); 
     }; 


     $scope.UserData = function ($scope) { 
      $scope.UserName = ""; 
      $scope.PassWord = ""; 
     }; 

     $scope.GetData = function() { 
      $http({ 
       url: " http://www.somesite.co.uk/ccuploader/campaigns/getCampaign", 
       method: "POST", 
       headers: {'Content-Type': 'application/x-www-form-urlencoded'} 
      }).then(function (response) { 
       // success 
       console.log('you have received the data '); 
       console.log("then : " + JSON.stringify(response)); 
       location.href = '/cms/index.html'; 
      }, function (response) { // optional 
       // failed 
       console.log('failed'); 
       console.log(JSON.stringify(response)); 
      }); 
     }; 
+0

$ scope.GetData()!= GetData() –

回答

2

您需要將您的代碼更新爲$scope.GetData();

當前您使用的是GetData(),它沒有引用相同的方法。實際上,根據錯誤消息,它是undefined

+0

啊,你這個人,謝謝 – Beep