【发布时间】:2012-01-03 13:31:27
【问题描述】:
我正在开发一个网络应用程序。在这里,我在 JavaScript 中创建了一个弹出窗口。现在我想在这个窗口内创建一个天气预报。
最简单的方法是什么?
我在这里做的:Get weather from Yahoo with jQuery
$(".popup-button").click(function(evt){
//prevent default link behavior
evt.preventDefault();
//get id from clicked element
var id = $(this).attr("id");
switch (id) {
case "popup-button-wetter":
//centering with css
centerPopup($("#popup-wrapper-wetter"));
//load popup
loadPopupadditional($("#popup-wrapper-wetter"));
//get weather
getWeather ()
break;
......
function getWeather () {
$.get("http://weather.yahooapis.com/forecastrss?w=782458&u=c", function(data){
console.log("Data Loaded: " + data);
});
}
});
但后来我得到了这个错误:
XMLHttpRequest 无法加载 http://weather.yahooapis.com/forecastrss?w=782458&u=c。 Access-Control-Allow-Origin 不允许使用原始文件://。
什么意思?
【问题讨论】:
标签: javascript xmlhttprequest weather weather-api