允许 API 的使用者访问视图 jQuery getJSON

发布于 2024-12-29 14:11:04 字数 171 浏览 1 评论 0原文

我目前有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

公布 2025-01-05 14:11:04

如果您尝试在向不同域发出请求的浏览器上运行一些 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.

素衣风尘叹 2025-01-05 14:11:04

通过 $.getJSON 传递的回调函数必须满足两个条件:

  • 它的参数必须按正确的顺序
  • 它必须在需要它的 API 的服务器上有一个接收器函数

这是一个图表:

CLIENT                   SERVER
------                   ------

Makes URL request        Looks up function matching this URL

Executes asynchonously   If found, executes function asynchonously

Returns from callback    Returns data from server side function, or error

The callback function passed with $.getJSON must satisfy two criteria:

  • Its arguments must be in the correct order
  • It must have a receiver function on the server of the API which expects it

Here is a diagram:

CLIENT                   SERVER
------                   ------

Makes URL request        Looks up function matching this URL

Executes asynchonously   If found, executes function asynchonously

Returns from callback    Returns data from server side function, or error

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文