Reputation: 13
I have problems to get data from Weather Underground from a historical day (same script works fine for my current observations). Example for yesterday:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script>
heute=new Date();
jahr=heute.getFullYear();
monat=heute.getMonth()+1;
tag = heute.getDate()-1;
jQuery(document).ready(function($) {
$.ajax({
url : "http://api.wunderground.com/api/ea1cb0c0f1995212/history_'+jahr+monat+tag+'/q/pws:INORDRHE156.json",
dataType : "jsonp",
success : function(parsed_json) {
var minhumidity = parsed_json.history.dailysummary[0].minhumidity;
var day = parsed_json.history.dailysummary[0].date.pretty;
document.getElementById("z8").innerHTML = minhumidity;
document.getElementById("z9").innerHTML = date;
}
});
});
</script>
So "day" works for me, output is: November 13, 2017
But "minhumidity" should bei '90' (or some other value), but there will be just a blank.
I get both values (day and minhumidity) at the same way, where is the Problem?
Sorry for my english.
Upvotes: 0
Views: 530
Reputation: 1074
your url "http://api.wunderground.com/api/ea1cb0c0f1995212/history_'+jahr+monat+tag+'/q/pws:INORDRHE156.json"
change it to (note that i changed ' with "):
<script>
heute=new Date();
jahr=heute.getFullYear();
monat=heute.getMonth()+1;
tag = heute.getDate()-1;
jQuery(document).ready(function($) {
$.ajax({
url : "http://api.wunderground.com/api/ea1cb0c0f1995212/history_"+jahr+monat+tag+"/q/pws:INORDRHE156.json",
dataType : "jsonp",
success : function(parsed_json) {
var minhumidity = parsed_json.history.dailysummary[0].minhumidity;
var day = parsed_json.history.dailysummary[0].date.pretty;
document.getElementById("z8").innerHTML = minhumidity;
document.getElementById("z9").innerHTML = date;
}
});
});
</script>
And please add var, let, const whatever to your variables. For example:
var heute = new Date();
var jahr = heute.getFullYear();
var monat = heute.getMonth()+1;
var tag = heute.getDate()-1;
Upvotes: 2