【问题标题】:Explanation and usage of JSONP [duplicate]JSONP的解释和使用[重复]
【发布时间】:2010-11-20 23:17:51
【问题描述】:

可能重复:
Please explain JSONP

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

【问题讨论】:

标签: ajax json jsonp


【解决方案1】:

【讨论】:

  • 谢谢,这篇文章不错。我确实意识到我也在寻找一些关于为什么它是必要的良好背景,这篇文章并没有真正涵盖,所以我将重新表述我的问题以包含它。
  • 来自文章“这样做,您可以进行跨域 JSON 请求。”这是一种绕过 xss 限制的方法
【解决方案2】:

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

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

我认为 JSONP 的主要用处是使用 <script> 标签跨域发出请求。我认为主要的缺点是,由于直接执行 JSONP,您必须相信远程站点不会发回任何恶意内容。但是我不得不承认我没有在实践中使用过这种技术。

编辑:Remote JSON - JSONP 提供了更多信息,说明您为什么要使用该技术的发明者。

【讨论】:

    【解决方案3】:

    引用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…

    【讨论】:

      猜你喜欢
      • 2011-10-19
      • 1970-01-01
      • 2015-07-29
      • 1970-01-01
      • 2011-04-19
      • 2020-08-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多