允许 API 的使用者访问视图 jQuery getJSON
我目前有一个 API,允许消费者通过 API 密钥使用。他们可以使用 cURL 或任何其他脚本语言进行调用 - 但不能调用视图 $.getJSON()。不返回任何结果,仅返回 HTTP 200 代码。
我是否需要将 crossdomain.xml 文件添加到服务器的根目录中,还是有其他方法?任何帮助将不胜感激。
I currently have an API that I allow consumers to use via an API key. They can make calls in cURL or any other scripting languages - but they can't make calls view $.getJSON(). No results are returned, only a HTTP 200 code.
Do I need to add a crossdomain.xml file to my servers' root directory or is there another way? Any help would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您尝试在向不同域发出请求的浏览器上运行一些 JavaScript,则由于 同源政策。您可以通过在提供 Web 内容的域上设置代理来解决此问题,该代理代表 JavaScript 访问您的 API。
crossdomain.xml 特定于 Flash,不会影响 JavaScript。
If you're trying to run some JavaScript on a browser that does a request to a different domain, it's simply not possible due to the same origin policy. You can work around this by setting up a proxy on the domain serving the web content which accesses your API on behalf of the JavaScript.
crossdomain.xml is specific to Flash and won't affect JavaScript.
通过 $.getJSON 传递的回调函数必须满足两个条件:
这是一个图表:
The callback function passed with $.getJSON must satisfy two criteria:
Here is a diagram: