成功登录后运行HTTP帖子

时间:2017-09-25 15:15:42

标签: javascript angularjs http callback

我有一个简单的登录,一旦用户登录,我已经添加了一个回调来运行另一个帖子,以便我可以访问我的系统中使用的帖子json。

我认为我做的方式是正确的,但是我收到了错误

  

未定义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));
            });
        };

1 个答案:

答案 0 :(得分:2)

您需要将代码更新为$scope.GetData();

目前您使用的GetData()并未引用相同的方法。事实上,根据错误消息,它是undefined