对预检请求的响应未通过访问控制检查:请求的资源上不存在“access-control-allow-origin”标头 [英] Response to preflight request doesn't pass access control check: no 'access-control-allow-origin' header is present on the requested resource

查看:137
本文介绍了对预检请求的响应未通过访问控制检查:请求的资源上不存在“access-control-allow-origin”标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

i am using ajax for web Api calling from C#.net . When i call the ajax function i geting this error 

<pre>Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:49956' is therefore not allowed access





和我的ajax函数是





and my ajax funcion is

$.ajax({
                        url: 'https://xxx.xxx.com/external/xx/token',
                        type: 'POST',
                        data: RequestBody,
                        Accept: 'Application/Json',
                        contentType: 'Application/Json',
                        headers: {
                            'Authorization':'Integration mOB33m0='
                        },
                        beforeSend: function(request) {
                            request.setRequestHeader("Authorization", "Integration bWE3Om0=");
                        },
                        success: function (data) {
                            debugger;
                           
                        },
                        error: function (xhr, textStatus, errorThrown) {
                            debugger;
                          

                        }

                    });





但我跑API通过Fiddler APi非常好用。这意味着API很好,我的代码中存在一些问题。哪里错了。



我尝试过的事情:





But i run the API through Fiddler the APi works very good. That means API is good there is a problem some were in my code . Where i am wrong .

What I have tried:

search in google but no appropriate answer i found.

推荐答案

.ajax({
url:' https://xxx.xxx.com/external/xx/token',
类型:'POST',
数据:RequestBody,
接受:'Application / Json',
contentType:'Application / Json',
标题:{
'授权':'集成mOB33m0 ='
},
beforeSend:function(request){
request.setRequestHeader(Authorization,Integration bWE3Om0 =);
},
成功:函数(数据){
调试器;

},
错误:function(xhr,textStatus,errorThrown){
debugger;


}

});
.ajax({ url: 'https://xxx.xxx.com/external/xx/token', type: 'POST', data: RequestBody, Accept: 'Application/Json', contentType: 'Application/Json', headers: { 'Authorization':'Integration mOB33m0=' }, beforeSend: function(request) { request.setRequestHeader("Authorization", "Integration bWE3Om0="); }, success: function (data) { debugger; }, error: function (xhr, textStatus, errorThrown) { debugger; } });





但我跑API通过Fiddler APi非常好用。这意味着API很好,我的代码中存在一些问题。哪里错了。



我尝试过的事情:





But i run the API through Fiddler the APi works very good. That means API is good there is a problem some were in my code . Where i am wrong .

What I have tried:

search in google but no appropriate answer i found.


这篇关于对预检请求的响应未通过访问控制检查:请求的资源上不存在“access-control-allow-origin”标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆