为什么要求站点返回错误Access-Control-Allow-Origin [英] Why request to site returns error Access-Control-Allow-Origin

查看:111
本文介绍了为什么要求站点返回错误Access-Control-Allow-Origin的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我正在向站点页面发出ajax请求,并且它不返回任何内容 - 页面是有效的,但在控制台中会出现此错误。访问控制 - 允许来源不允许起源 http:// localhost



如何解决这个问题,我不能正确地连接到页面。

解决方案

由于浏览器相同的来源策略,您会看到此错误,从而阻止对其他域和子域进行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屋!

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