[英]Server responded with a status of 401 - No 'Access-Control-Allow-Origin' header - Angular Js - working fine with Jquery Ajax
Client side : AngularJS 客户端: AngularJS
Server / tech : Apache / Java Spring 服务器/技术: Apache / Java Spring
First error was the No Access Control Allow Origin header not present. 第一个错误是没有访问控制允许原始标头。 We fixed that by adding this code to the server side. 我们通过将此代码添加到服务器端来解决此问题。 The request is working fine with postman . 邮递员的要求很好。
In Controller function http get method is returning error 401 (Unauthorized). 在Controller函数中,http get方法返回错误401(未授权)。
$http.get("our_local_url").then(function(data) {
console.log("data:"+data);
}, function(error) {
console.log("error:"+error);
});
A Test page with Jquery Ajax Call is working fine with the code 带有Jquery Ajax Call的Test页面可以很好地使用代码
$.ajax({
url: "our_local_url",
type: "GET",
success: function(result){
console.log(result);
},
error: function(xhr,status,error){
console.log(error);
}
});
I've gone through several SO answers before asking this. 在问这个之前,我已经经历了几个SO答案。
Add withCredentials: true
in service call 添加withCredentials: true
在服务调用中为withCredentials: true
try this below 在下面试试
$http.get("our_local_url", { withCredentials: true }).then{...};
There was some security handling in the spring-security which was blocking the call. spring-security中进行了一些安全处理,阻止了呼叫。 After it's removed, it worked (No Access Control Allow Origin header added). 删除后,它起作用了(没有添加访问控制允许源头)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.