Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as JavaScript by prova ( 14 years ago )
function loadCurrentWeather() {
x$.data = {};
var _dom = new Object();
x$("body").xhr("http://www.google.co.za/ig/api?weather=Cape+Town",
{ async: true,
callback: function(){
if (this.status = '200') {
var xmlResp = this.responseXML;
/** CURRENT CONDITIONS*/
var current_info = xmlResp.getElementsByTagName("current_conditions"); //an array of elements/records
x$(current_info).each(function(element, index, xui) {
var city = 'Cape Town, South Africa';
var icon = element.getElementsByTagName("icon")[0].getAttribute('data');
var curr_temp = element.getElementsByTagName("temp_c")[0].getAttribute('data');
var humidity = element.getElementsByTagName("humidity")[0].getAttribute('data');
var wind_condition = element.getElementsByTagName("wind_condition")[0].getAttribute('data');
var img_src = '<img />';
document.getElementById("weather-current-location")[removed] = city;
document.getElementById("weather-current-icon")[removed] = img_src;
document.getElementById("weather-current-temp")[removed] = "Temp: " + curr_temp + "ºC";
document.getElementById("weather-current-humidity")[removed] = humidity;
document.getElementById("weather-current-wind")[removed] = wind_condition;
});
} else {
alert("XHR Failure: " + this.status);
}
}
}
);
}
/**
* Using XUI XHR
*/
function loadForecastWeather() {
x$.data = {};
var _dom = new Object();
x$("body").xhr("http://www.google.co.za/ig/api?weather=Cape+Town",
{ async: true,
callback: function(){
if (this.status = '200') {
var xmlResp = this.responseXML;
/** FORECAST CONDITIONS*/
var forecast_info = xmlResp.getElementsByTagName("forecast_conditions"); //an array of elements/records
x$(forecast_info).each(function(element, index, xui) {
var dow = element.getElementsByTagName("day_of_week")[0].getAttribute('data');
var icon = element.getElementsByTagName("icon")[0].getAttribute('data');
var low = element.getElementsByTagName("low")[0].getAttribute('data');
var high = element.getElementsByTagName("high")[0].getAttribute('data');
var img_src = '<img />';
// convert to Celcius
low = ((low - 32) / 1.8);
high = ((high - 32) / 1.8);
document.getElementById("weather-forecast-dow-"+index)[removed] = dow;
document.getElementById("weather-forecast-icon-"+index)[removed] = img_src;
document.getElementById("weather-forecast-tmp-low-"+index)[removed] = low.toFixed(0) + "ºC";
document.getElementById("weather-forecast-tmp-high-"+index)[removed] = high.toFixed(0) + "ºC";
});
} else {
alert("XHR Failure: " + this.status);
}
}
}
);
}
Revise this Paste