如何从加载XML文件
http://weather.yahooapis.com/forecastrss?w=12766488&u=f以及如何使用它。我可以使用JavaScript或PHP,但每当我尝试使用JavaScript时,它都会抛出这个错误:
XMLHttpRequest cannot load http://weather.yahooapis.com/forecastrss?w=12766488&u=f. Origin http://localhost:6574 is not allowed by Access-Control-Allow-Origin.发布于 2013-10-18 08:47:26
您可以使用PHP作为代理。请求到您的域(是的,您使用AJAX),将您想要查看的url发送给它:
http://mydomain.com/external.php?url=http%3A%2F%2Fweather.yahooapis.com%2Fforecastrss%3Fw%3D12766488%26u%3Df然后创建一个PHP页面(在本例中为external.php),获取请求的外部URL,并使用file_get_contents等函数检索外部URL的内容。然后,无论该请求返回什么,都将结果作为对AJAX的响应返回。
echo file_get_contents(urlencode($_GET['url']));https://stackoverflow.com/questions/19439728
复制相似问题