0

How do you load the XML file from

http://weather.yahooapis.com/forecastrss?w=12766488&u=f

and how do you use it. I can either use JavaScript or PHP, but whenever I try with JavaScript, it throws this error:

XMLHttpRequest cannot load http://weather.yahooapis.com/forecastrss?w=12766488&u=f. Origin http://localhost:6574 is not allowed by Access-Control-Allow-Origin.
vcapra1
  • 1,988
  • 3
  • 26
  • 45
  • And btw what now? If PHP works, why don't you use PHP for that. Just asking, it's not so clear from your quesiton. Or you *need* that in Javascript but you already could get it to work with PHP? – hakre Oct 23 '13 at 15:43

1 Answers1

0

You can use PHP as a proxy. Request to your domain (yes, you do AJAX), sending it the url you want to view:

http://mydomain.com/external.php?url=http%3A%2F%2Fweather.yahooapis.com%2Fforecastrss%3Fw%3D12766488%26u%3Df

Then have a PHP page (external.php in this case) get the requested external URL and retrieve the external URL's contents using some function like file_get_contents. Then whatever is returned by that request, return the results back as response to your AJAX.

echo file_get_contents(urlencode($_GET['url']));
Joseph
  • 117,725
  • 30
  • 181
  • 234