为什么要求站点返回错误Access-Control-Allow-Origin [英] Why request to site returns error Access-Control-Allow-Origin
问题描述
如何解决这个问题,我不能正确地连接到页面。
由于浏览器相同的来源策略,您会看到此错误,从而阻止对其他域和子域进行XML HTTP请求(AJAX)。 JSONP在很多开发者中都受到青睐。但是,这需要您提出请求的服务器/页面为JSONP响应提供服务。
Ok so, i'm making ajax request to site page, and it doesn't return anything - page is valid, but it gives this error in the console . Origin http://localhost is not allowed by Access-Control-Allow-Origin.
How to fix it, i wan't to connect to the page properly.
You are seeing this error because of browsers Same origin policy which prevents XML HTTP requests(AJAX) to be made to other domains and sub-domains. There are many workarounds of which JSONP is favoured among many developers. But, this requires the server/page to which you're making the request to serve JSONP response.
这篇关于为什么要求站点返回错误Access-Control-Allow-Origin的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!