什么是 JSONP,为什么创建它? [英] What is JSONP, and why was it created?

查看:34
本文介绍了什么是 JSONP,为什么创建它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解 JSON,但不了解 JSONP.维基百科关于 JSON 的文档 是(曾经)JSONP 的顶级搜索结果.它是这样说的:

I understand JSON, but not JSONP. Wikipedia's document on JSON is (was) the top search result for JSONP. It says this:

JSONP 或带填充的 JSON"是一个 JSON 扩展,其中前缀被指定为调用本身的输入参数.

JSONP or "JSON with padding" is a JSON extension wherein a prefix is specified as an input argument of the call itself.

嗯?什么叫?这对我来说没有任何意义.JSON 是一种数据格式.没有电话.

Huh? What call? That doesn't make any sense to me. JSON is a data format. There's no call.

第二个搜索结果来自一个名叫Remy,他写了这篇关于 JSONP 的文章:

The 2nd search result is from some guy named Remy, who writes this about JSONP:

JSONP 是脚本标记注入,将来自服务器的响应传递给用户指定的函数.

JSONP is script tag injection, passing the response from the server in to a user specified function.

我可以理解这一点,但仍然没有任何意义.

I can sort of understand that, but it's still not making any sense.

那么什么是 JSONP?为什么创建它(它解决了什么问题)?我为什么要使用它?

So what is JSONP? Why was it created (what problem does it solve)? And why would I use it?

附录:我刚刚为 JSONP 创建了一个新页面 在维基百科上;它现在根据 jvenema 的回答对 JSONP 进行了清晰而全面的描述.

Addendum: I've just created a new page for JSONP on Wikipedia; it now has a clear and thorough description of JSONP, based on jvenema's answer.

推荐答案

其实并不复杂...

假设您在域 example.com 上,并且您想向域 example.net<发出请求/强>.为此,您需要跨域边界,这是大多数浏览器领域的禁忌.

Say you're on domain example.com, and you want to make a request to domain example.net. To do so, you need to cross domain boundaries, a no-no in most of browserland.

绕过此限制的一项是

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆