2017-09-25 69 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