Ajax 使用Firefox在AngularJS中成功回调$http.post
我在AngularJS应用程序中进行了一个简单的CORS AJAX调用,调用成功:Ajax 使用Firefox在AngularJS中成功回调$http.post,ajax,angularjs,post,cors,Ajax,Angularjs,Post,Cors,我在AngularJS应用程序中进行了一个简单的CORS AJAX调用,调用成功: $http({method:'POST',url:"http://0.0.0.0:4567/authenticate", params: {Lusername:scope.Lusername,Lpassword:scope.Lpassword}}) .success(function(){alert("Success")}) 在Safari中使用时,它工作正常:返回预期的JSON对象并显示警报框。但是,在
$http({method:'POST',url:"http://0.0.0.0:4567/authenticate",
params: {Lusername:scope.Lusername,Lpassword:scope.Lpassword}})
.success(function(){alert("Success")})
在Safari中使用时,它工作正常:返回预期的JSON对象并显示警报框。但是,在Firefox中,虽然JSON对象被正确返回,但不会触发成功回调
知道为什么吗?确保在服务器中处理选项请求。如果返回404,那么Firefox将不会调用下一个请求(在您的情况下是上面提到的帖子)。使用AngularJS的最新版本尝试此操作:
$http.post("http://0.0.0.0:4567/authenticate", {
Lusername: $scope.Lusername,
Lpassword: $scope.Lpassword
}).success(function(data, status, headers, config) {
alert("Success");
});
你有一个可以重现问题的JSFIDLE吗?顺便说一下,我知道这只是一个例子,但考虑使用$window.alert()而不是alert()(您注入的服务在哪里)。CORS的可能性。检查。如果我无法访问服务器选项,该怎么办:)需要在服务器上设置CORS。这不能解释问题,也不能帮助将来可能遇到类似问题的任何其他人。