JSONP解释及使用

发布于 2024-08-02 11:32:01 字数 198 浏览 3 评论 0原文

可能的重复:
请解释一下 JSONP

什么是 JSONP,为什么需要它,以及它的一些实际用法示例。

Possible Duplicate:
Please explain JSONP

What is JSONP, why is it needed, and what are some real world examples of it's usage.

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

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

发布评论

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

评论(3

好听的两个字的网名 2024-08-09 11:32:01

JSONP 代表带有填充的 JSON,它为客户端提供了一种方法来指定应添加到 JSON 响应开头的一些代码。这允许 JSONP 响应直接在浏览器中执行。 JSONP 响应的一个示例可能是:

processResults({value1: "Hello", value2: "World"})

我认为 JSONP 有用的主要地方是使用

编辑:远程 JSON - JSONP 提供了有关的更多信息为什么你想要使用似乎发明了该技术的人的技术。

JSONP stands for JSON with padding, and it provides a way for the client to specify some code that should be added to the start of the JSON response. This allows the JSONP response to be directly executed in the browser. An example of a JSONP response might be:

processResults({value1: "Hello", value2: "World"})

I think the major place that JSONP would be useful is in making requests across domains using the <script> tag. I think the major disadvantage is that as the JSONP is directly executed you would have to trust that the remote site wouldn't send back anything malicious. However I have to admit that I haven't used the technique in practice.

Edit: Remote JSON - JSONP provides more information on why you would want to use the technique from the guy who appears to have invented it.

-柠檬树下少年和吉他 2024-08-09 11:32:01

引用自此博客

JSONP 的目的是克服臭名昭著的同域策略的边界,该策略将 XHR 请求限制到同一域,这意味着您无法向其他域发出 Ajax 请求。使用 JSONP 无需担心这个问题,因为它甚至不需要 Ajax 即可工作;它所做的只是使用脚本标签和回调......

Quoting from this blog:

The purpose of JSONP is to overcome the boundaries of the infamous same-domain-policy which restricts XHR requests to the same domain meaning that you cannot make Ajax requests to other domains. There’s no need to worry about that with JSONP because it doesn’t even require Ajax to work; all it’s doing is using script tags and callbacks…

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