Mam taką funkcję w JavaScript:
function widget(src){
function zeroWiodace(i) {
return (i < 10)? '0'+i : i;
}
var temperatura = null;
jQuery.get('http://'+window.location.host+'/weather.xml', {}, function(xml){
var czas = new Date();
var now = czas.getDate()+'-'+zeroWiodace((czas.getMonth() + 1))+'-'+czas.getFullYear();
jQuery('day', xml).each(function(i){
if (jQuery(this).find("data").text() === now){
temperatura = jQuery(this).find("temperatura").text();
}
});
});
//alert('temp: '+temperatura);
document.write(
'<div class="w-plugin-box">'+
'<div class="w-plugin-map">'+
'<h3 class="w-plugin-header">'+
'Warszawa<br />'+
'</h3>'+
'</div>'+
'</div>'+
'<style type="text/css">'+
'.w-plugin-header{color: #fff;font-size: 1.3em;padding: 100px 50px;}'+
'.w-plugin-map{width: max-width: 240px;max-height: 240px;background: url('+src+'/images/krakow.png) no-repeat; background-size: 100% 100%;width: 240px;height: 240px;}'+
'</style>'
);
jQuery('.w-plugin-header').append('<strong>'+temperatura+'</strong>');
}
Ogólnie funkcja pobiera dane z XML i szuka wartości z dnia dzisiejszego. Lecz problem mam z tym, że jeśli już znajdzie wartość:
temperatura = jQuery(this).find("temperatura").text();
to potem nie mogę jej wyświetlić. Jeśli odkomentuję //alert('temp: '+temperatura); wtedy w ostatniej linii wartość jest dodana. Jeśli jest zakomentowane, otrzymuję w html "undefined".
Nie rozumiem kompletnie dlaczego tak się dzieje. Pomoże ktoś?