如何允许访问控制标题访问跨域的远程API?
问题描述:
我开发一个移动应用程序,我通过远程API得到我的数据,但我的javascript程序返回以下错误:如何允许访问控制标题访问跨域的远程API?
XMLHttpRequest cannot load http://na.lolesports.com/api/standings.json?tournamentId=225 . No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin ... is therefore not allowed access.
答
有没有什么你可以在你做到底,在CORS设置为API将不得不改变。事实上,它们是专门不允许跨站点的起源,因为他们不想让第三方访问其API:
https://developer.riotgames.com/discussion/community-discussion/show/GokMZKKl
如果我记得没错出现这种情况是在服务器端不把HTTP响应中的正确跨域标头。 – Okazari
如果API提供JSONP,则应使用 – 2015-07-21 14:31:23
,如果将此URL输入到浏览器中,则会获得响应:http://na.lolesports.com:80/api/schedule.json?tournamentId=230&includeFinished=true&includeFuture=false&includeLive =假 也可使用一个Chrome扩展这里:https://www.google.fr/webhp?sourceid=navclient&hl=fr&ie=UTF-8#hl=fr&q=chrome+extension+allow+origin 它完美在本地使用此Chrome扩展程序,我只想在没有扩展名的情况下执行相同操作。 – eLearner