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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,每个请求都会产生一个新的
标记,是的,当您使用完它提供的数据后,您可以删除
标记你。
您应该考虑使用 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.