Javascript 成功登录后运行HTTP post
我有一个简单的登录,一旦用户登录,我就添加了一个回调来运行另一个post,这样我就可以访问post json以在我的系统中使用 我认为我这样做是正确的,但我得到了错误 未定义GetData 这是正确的方法吗 JavaScriptJavascript 成功登录后运行HTTP post,javascript,angularjs,http,callback,Javascript,Angularjs,Http,Callback,我有一个简单的登录,一旦用户登录,我就添加了一个回调来运行另一个post,这样我就可以访问post json以在我的系统中使用 我认为我这样做是正确的,但我得到了错误 未定义GetData 这是正确的方法吗 JavaScript $scope.LogIn = function () { $http({ url: "http://www.somesite.co.uk/ccuploader/users/login",
$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));
});
};
您需要将代码更新为
$scope.GetData()代码>
当前您使用的是GetData()
,它没有引用相同的方法。事实上,根据错误消息,它是未定义的。$scope.GetData()!=GetData()