Javascript cross-domain XML loading using iframe-proxy / xsl / jsonp hybrid concept?

On our site www.foo.comwe want to download and use http://feeds.foo.com/feed.xmlwith Javascript. We will obviously use Access-Control , but for browsers that do not support it, we consider the following as a reserve:

Inwww.foo.com we install document.domain, provide a callback function and load the feed into (hidden) iframe:

document.domain = 'foo.com';
function receive_data(data) {
 // process data
};

var proxy = document.createElement('iframe');
proxy.src = 'http://feeds.foo.com/feed.xml';
document.body.appendChild(proxy);

Infeeds.foo.com add XSL to feed.xmland use it to convert the feed to an html document that also installs document.domainand calls the callback function in its parent using a data feed like json:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
 <xsl:template match="ROOT">
  <html><body>
   <script type="text/javascript">
    document.domain = 'foo.com';
    parent.receive_data([<xsl:apply-templates/>]);
   </script>
  </body></html>
 </xsl:template>
 <!-- templates that transform data into json objects go here -->
</xsl:stylesheet>

XML feeds.foo.com iframe-proxy/xslt/jsonp? (.. ?)


+3
2

, , ​​ EasyXDM, - quirks API script (, postMessage , , ).

: , ( "" , ). .

: - , script!

+1

yahoo apis (YQL). URL-,

, :)

+2

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


All Articles