jQuery“访问被拒绝”错误

发布于 2024-09-02 05:38:34 字数 154 浏览 7 评论 0原文

我有一个 $.ajax() 请求,该请求从另一个 Web 服务器查询货币汇率信息,这就是我在 $.ajax() 上收到“访问被拒绝”错误的原因(我相信) code>$.ajax() 调用。

有没有办法允许这种类型的活动?

I have an $.ajax() request that queries currency exchange rate information from another web server, which is the reason (I believe) for which I am getting an "Access Is Denied" error on the $.ajax() call.

Is there a way to permit this type of activity?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

十二 2024-09-09 05:38:34

是的,如果远程服务器可以支持它(仅适用于 GET 请求,并且适用于 .ajax 函数以及)。另一种选择是在同一域上创建桥接服务器脚本。

这是一篇文章,可以帮助您入门。

它的工作原理如下:

服务器必须使用以下格式发送数据:

callback({name : "Smith", id : 1})

其中 callback 必须是可配置的。

所以基本上 jQuery 在 DOM 中包含一个 script 标签:

<script type="text/javascript" src="http://distantdomain.com/?jsonp_callback=someRandomName"></script>

并且 someRandomName 函数将被执行并传递 JSON 对象。

Yes, you could use JSONP if the remote server can support it (works only with GET requests and it works with the .ajax function as well). Another option is to create a bridge server script on the same domain.

Here's an article that may help you get started.

Here's how it works:

The server must send the data using the following format:

callback({name : "Smith", id : 1})

where callback must be configurable.

So basically jQuery includes a script tag inside the DOM:

<script type="text/javascript" src="http://distantdomain.com/?jsonp_callback=someRandomName"></script>

and the someRandomName function will be executed and passed the JSON object.

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