[英]AngularJS Origin http://localhost:8080 is not allowed by Access-Control-Allow-Origin
I'm developing a web app with AngularJS. 我正在使用AngularJS开发Web应用程序。 It consists in an admin interface that rely on an json-rpc API that resides on another domain. 它包含一个管理界面,该界面依赖于另一个域上的json-rpc API。
In my local enviroment, if I make a Request (with AngularJS) to API server I get the error "Origin http://localhost:8080 is not allowed by Access-Control-Allow-Origin" in my console Browser". 在我的本地环境中,如果我向API服务器发出请求(使用AngularJS),则会收到错误“控制台浏览器中的Access-Control-Allow-Origin不允许访问http:// localhost:8080 ”。
I've read the limit of modern browsers to blocking the request to another domain, but.... if there is no solution... Do I need to create my web service (with one backend language: es: PHP or Python) that make requests to API web server and then make the AngularJS request to this? 我已经读过现代浏览器的限制,无法将请求阻止到另一个域,但是....如果没有解决方案...我是否需要创建我的Web服务(使用一种后端语言:es:PHP或Python)向API Web服务器发出请求,然后对此发出AngularJS请求?
Why I need another "web server" in the middle of my application infrastructure? 为什么在我的应用程序基础结构中间需要另一个“ Web服务器”?
Thanks in advance. 提前致谢。 F. F。
Update: I've read about crossdomain.xml file here: http://www.adobe.com/devnet/adobe-media-server/articles/cross-domain-xml-for-streaming.html 更新:我已经在这里阅读了有关crossdomain.xml的文件: http : //www.adobe.com/devnet/adobe-media-server/articles/cross-domain-xml-for-streaming.html
Does it could be, in someway, the solution of my problem? 在某种程度上,这是否可以解决我的问题?
Because server must send headers with CORS enabled when responding to ajax requests. 因为服务器在响应ajax请求时必须发送启用了CORS的标头。 Something like: 就像是:
'Access-Control-Allow-Origin', '*' “访问控制允许来源”,“ *”
'Access-Control-Allow-Credentials', true “访问控制允许凭据”,true
'Access-Control-Allow-Methods', 'POST, GET, PUT, DELETE, OPTIONS' “访问控制允许方法”,“ POST,GET,PUT,DELETE,OPTIONS”
'Access-Control-Allow-Headers', 'Content-Type' “访问控制允许标题”,“内容类型”
But read more about CORS to protect your server. 但是,请阅读有关CORS的更多信息,以保护您的服务器。 Current internet browsers checks for these headers when You are sending ajax communication. 当前的Internet浏览器在发送ajax通信时会检查这些标头。 It is for security reasons. 出于安全原因。
Having a web server is always an option, but if you want to stay on the client, consider using JSONP. 拥有Web服务器始终是一种选择,但是如果您希望保留在客户端上,请考虑使用JSONP。 Read about it here: What is JSONP all about? 在这里阅读: JSONP的全部含义是什么?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.