我们使用Spring Security
插件运行外部Grails
服务器应用程序。 前端在本地运行AngularJS
。AJAX请求被AngularJS和Spring Security取消
每当我尝试登录,请求立即取消..显着AngularJS发送一个GET
请求首先与OPTIONS
方法;这返回一个200 OK
响应就好了。 实际的POST
请求永远不会到达服务器,但是有什么可能取消我的请求?
下面的代码:
$scope.login = function() {
$http.defaults.headers.common["X-Requested-With"] = "XMLHttpRequest";
$scope.loggingIn = true;
// Setup Config
var data = {
j_username: $scope.user.email,
j_password: $scope.user.password
}
var config = {method: 'POST', url: serverUri+'/j_spring_security_check/', data: data};
// Dispatch HTTP Request
$http(config)
.success(function(data, status, headers, config) {
if (data.status) {
// successful login
User.isLogged = true;
User.username = data.username;
}
else {
User.isLogged = false;
User.username = '';
}
$scope.loggingIn = false;
console.log("NOICE!");
})
.error(function(data, status, headers, config) {
$scope.loggingIn = false;
User.isLogged = false;
User.username = '';
if (status == 0) {
// Request got cancelled
console.log("Request got cancelled.");
return;
}
});
}
这是取消要求是什么样子:http://i.stack.imgur.com/kiWnb.png
这是OPTIONS
要求是什么样子:http://i.stack.imgur.com/FAj96.png