Chrome显示访问控制允许原点错误 [英] Chrome shows Access Control Allow Origin error

查看:117
本文介绍了Chrome显示访问控制允许原点错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jquery将数据发布到服务器,服务器接收到数据,但是chrome仍然显示错误:

I'm using jquery to post data to a server, the server received the data, but the chrome still shows the error :

XMLHttpRequest cannot load `myServer:63373/api/sendData`. Origin `myServer:63385` is not allowed by Access-Control-Allow-Origin. 

这是我的js代码:

 $.ajax({
            type: 'POST',
            url: 'myServer:63373/api/SendData',
            crossdomain: true,
            async: true,
            data: myData,
            dataType: 'json',
            success: function(){ alert('success'); }
        });

奇怪的是,成功"出现在请求之后,服务器确实收到了数据,但随后错误消息出现在控制台中.有什么办法可以避免此消息?

The strange thing is that the 'success' shows up after the request, and the server did receive the data, but then the error message shows up in the console. Is there any way to avoid this message?

推荐答案

感谢您的上述回答,但我想我已经找到了解决方法,在解决此问题之前,我尝试使用两种方法,

Thanks for all you answers above but I think I've found the way, before I solve this I was trying to use two ways, Setting Access-Control-Allow-Origin in ASP.Net MVC - simplest possible method with the 87 votes and 32 votes, I found the answers at two different places, and both applied them, but it didn't work. Early this week, I tried to delete the code in the web.config and just left the code in C#, it works! Can't believe these two solutions have confliction.

无论如何,希望这可以对其他人有所帮助.

Anyway, hope this could help others.

这篇关于Chrome显示访问控制允许原点错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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