简体   繁体   English

服务器响应状态为401-无“ Access-Control-Allow-Origin”标头-Angular Js-与Jquery Ajax配合正常

[英]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.

相关问题 jQuery Ajax登录中没有“ Access-Control-Allow-Origin”标头 - No 'Access-Control-Allow-Origin' Header In jQuery Ajax Login jQuery Ajax不起作用-否'Access-Control-Allow-Origin' - Jquery ajax not working - No 'Access-Control-Allow-Origin' 请求的资源上没有“Access-Control-Allow-Origin”标头+响应具有HTTP状态代码401 - No 'Access-Control-Allow-Origin' header is present on the requested resource + The response had HTTP status code 401 xmla4js我不断获取Origin null是Access-Control-Allow-Origin ajax标头不允许的 - xmla4js I keep getting Origin null is not allowed by Access-Control-Allow-Origin ajax header AJAX请求中不存在“ access-control-allow-origin”标头 - No 'access-control-allow-origin' header is present in AJAX request ReactJS localhost Ajax调用:没有“ Access-Control-Allow-Origin”标头 - ReactJS localhost Ajax call: No 'Access-Control-Allow-Origin' header AJAX请求中没有“ Access-Control-Allow-Origin”标头存在错误 - No 'Access-Control-Allow-Origin' header is present error in AJAX Request Ajax和本地网络给出“没有'Access-Control-Allow-Origin'标头” - Ajax And Local Network gives “No 'Access-Control-Allow-Origin' header” 角度4-所请求的资源上没有“ Access-Control-Allow-Origin”标头 - Angular 4 - No 'Access-Control-Allow-Origin' header is present on the requested resource 角$ http.post并且没有'Access-Control-Allow-Origin'标头 - Angular $http.post and No 'Access-Control-Allow-Origin' header
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM