Beep Beep - 27 days ago 6
AngularJS Question

Run HTTP post on successful post login

I have a simple login, once user is logged in I have added a call back to run another post so that I have access to the post json to use in my system.

I think the way I have done it is correct however I am getting error


GetData is not defined


Is this the correct way to do this

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));
});
};

Answer Source

You need to update your code to be $scope.GetData();.

Currently you are using GetData() which doesn't reference the same method. In fact it is undefined as per the error message.