开发者

Does JSONP scale? How many JSONP requests can I send before my page fills up with <script> tags?

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,开发者_JAVA百科 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜