JSONP 可以扩展吗?在我的页面被

基于 请解释 JSONP,我了解 JSONP 可用于绕过同源策略。

但为了做到这一点,页面必须使用

我知道页面可以动态发出新的脚本标签,例如 with:

<script type="text/javascript" language='javascript'>

  document.write('<script type="text/javascript" ' + 
                 'id="contentloadtag" defer="defer" ' +
                 'src="javascript:void(0)"><\/script>');
  var contentloadtag=document.getElementById("contentloadtag");
  contentloadtag.onreadystatechange=function(){
    if (this.readyState=="complete") { init(); }
  }
</script>

(以上在 IE 中有效,不要认为它在 FF 中有效)。

...但这是否意味着每个 JSONP 调用都需要我向文档中发出另一个

Based on Please explain JSONP, I understand that JSONP can be used to get around the same-origin policy.

But in order to do that, the page must use a <script> tag.

I know that pages can dynamically emit new script tags, such as with:

<script type="text/javascript" language='javascript'>

  document.write('<script type="text/javascript" ' + 
                 'id="contentloadtag" defer="defer" ' +
                 'src="javascript:void(0)"><\/script>');
  var contentloadtag=document.getElementById("contentloadtag");
  contentloadtag.onreadystatechange=function(){
    if (this.readyState=="complete") { init(); }
  }
</script>

(the above works in IE, don't think it works in FF).

... but does this mean, effectively, that every JSONP call requires me to emit another <script> tag into the document? Can I remove the <script> tags that are done?

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

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

发布评论

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

评论(1

自控 2024-09-01 04:01:20

是的,每个请求都会产生一个新的

您应该考虑使用 JSONP 的 Javascript 库。 OX.AJAST 是一个简单的库,我前段时间写过通过脚本标签(即JSONP)跨浏览器进行异步请求的文章。 YUI 还支持 JSONP(如果您已经在使用它)。

Yes, every request yields a new <script> tag, and yes, you can remove <script> tags when you're done using the data that it provides to you.

You should consider using a Javascript library for JSONP. OX.AJAST is a simple library I wrote some time ago for doing asynchronous request through script tags (i.e. JSONP) across browsers. YUI also supports JSONP if you're already using that.

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