Javascript 在http.get函数返回之前调用的函数
我有一个angular控制器,它发出一个HTTP GET请求,在promise返回时,调用success of error函数。我现在的代码有时会在GET请求返回后执行success函数,有时会在GET请求返回前执行。在我的承诺处理过程中有什么我搞砸了吗?需要注意的是,有时候http GET甚至没有被调用(或者至少没有被调用的断点),成功函数也会发生。这是我的密码:Javascript 在http.get函数返回之前调用的函数,javascript,angularjs,promise,angular-promise,Javascript,Angularjs,Promise,Angular Promise,我有一个angular控制器,它发出一个HTTP GET请求,在promise返回时,调用success of error函数。我现在的代码有时会在GET请求返回后执行success函数,有时会在GET请求返回前执行。在我的承诺处理过程中有什么我搞砸了吗?需要注意的是,有时候http GET甚至没有被调用(或者至少没有被调用的断点),成功函数也会发生。这是我的密码: .controller('CheckOutCtrl', ['$scope', '$http', function($scope,
.controller('CheckOutCtrl', ['$scope', '$http', function($scope, $http) {
//Controller for checkout feature
$scope.owner = "Unclaimed"; //Default owner
$scope.endDate = "";
$scope.unclaimed = true;
$scope.showpopup = false; //Should we show the popup that checkout is successful or returned
$scope.currentOwner = false; //Show return date
$scope.popuptext = "";
$scope.checkOut = function(){ //Extends or creates a check out
$http.get("/checkout/extend/code/" + code + "/username/" + userName).then(
function success(response, status, headers, config) {
console.log("Checked out or extended");
$scope.showpopup = true;
$scope.currentOwner = true;
$scope.popuptext = response.data; //Show airport checked out until or error
console.log($scope.popuptext);
init(); //Update current owner
},
function error(response, status, headers, config) {
$scope.error = response;
console.error("Check out error:", response);
}
);
};
}
我发现发生这种情况是因为角度缓存获取请求已经有一段时间了,并且正在使用我请求的缓存版本。尝试这种方式
。然后(函数(success){console.log(success.data)},函数(e){console.log(e)}
@AshikBasheer存在相同问题您在哪里调用签出功能?是否“code”和“userName”未定义?另外,URL是否正确?检查网络选项卡以了解实际情况response@lifetimeLearner007URL是正确的,变量也是正确的。有时请求正确通过,但大多数情况下请求从未通过H