Is the JSONP scale? How many JSONP requests can I send before my page is populated with <script> tags?

Based on Please explain JSONP , I understand that JSONP can be used to circumvent a policy of the same origin.

But for this, the page must use the <script> .

I know that pages can dynamically generate new script tags, for example:

 <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, do not think that it works in FF).

... but does this really mean that every JSONP call requires me to release another <script> in the document? Can I remove the <script> tags that have been executed?

+4
source share
1 answer

Yes, each request gives a new <script> , and yes, you can remove the <script> tags when you are done using the data you provided.

You should consider using the Javascript library for JSONP. OX.AJAST is a simple library that I wrote some time ago to execute an asynchronous request through script tags (i.e. JSONP) in browsers. YUI also supports JSONP if you are already using this.

+2
source

Source: https://habr.com/ru/post/1304145/


All Articles