Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can JavaScript load XML data from a third-party domain?

Can JavaScript load an RSS XML feed from Yahoo?

Is client-side JS allowed to access 3rd-party domains?

like image 819
Robin Rodricks Avatar asked Mar 19 '09 01:03

Robin Rodricks


People also ask

Can JavaScript read XML?

Several key methods and properties in JavaScript can help in getting information from an XML file. In the section, a very simple XML file is used to demonstrate pulling data from XML into an HTML page using JavaScript to parse (interpret) the XML file.

What is cross domain XML?

A cross-domain policy is simply a user-defined set of permitted data access rules encapsulated in a crossdomain. xml file. It is only viable on servers that communicate via HTTP, HTTPS, or FTP. A cross-domain policy file is an XML document that grants a web client permission to handle data across one or more domains.

What is use of XML HTTP Request object explain its use with help of simple JavaScript code?

The XMLHttpRequest object can be used to request data from a web server. The XMLHttpRequest object is a developer's dream, because you can: Update a web page without reloading the page. Request data from a server - after the page has loaded.

Which of the following step occurs after webserver returns the result containing XML document?

Steps of AJAX Operation The XMLHttpRequest object makes an asynchronous request to the Webserver. The Webserver returns the result containing XML document. The XMLHttpRequest object calls the callback() function and processes the result. The HTML DOM is updated.


2 Answers

You can use the technique outlined in my blog post Unwritten guide to Yahoo Query Langauge

You would query the XML data table with a yql statment like this:

select * from xml
  where url="http://path/to/xml
Then you would add a script tag to your html (can be done with document.createElement('script')) with a src http://query.yahooapis.com/v1/public/yql?q={your yql here}&format=json&callback={your function here} where {your yql here} is replace with a URI Encoded version of you yql statment.

like image 138
jasonincode Avatar answered Sep 25 '22 14:09

jasonincode


An easy way to do this is to proxy the request through the server that your page resides on. Steps are:

  1. Write a server side script performs an http request on the rss feed, when that script itself is request (i.e. via get or post)
  2. Use ajax to request the server side script, or just call it from the main script for that page.
  3. The server side script then returns the feed source in some displayable form.
  4. Profit!

On IE 8 and FF 3.1(not certain), it is possible to make these requests through specialized cross site calls, but the last generation of browsers will still cause problems. See:

http://dannythorpe.com/2009/01/15/ie8-cross-domain-request-support-demo/ http://ejohn.org/blog/cross-site-xmlhttprequest/ Feature is restricted in FF 3.0, unclear if it will be back in 3.1

However, the steps above are guaranteed not to run afoul of any browser CSS security, at the expense of some lag and extra hw load on your server.

like image 35
Dana the Sane Avatar answered Sep 21 '22 14:09

Dana the Sane