Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdate API content on webpage with XMLHttpRequest?
    primarykey
    data
    text
    <p>I am trying to update content from a weather service API on my webpage by using XMLHttpRequest.</p> <p>Unfortunately i'm new to using this javascript functionality. I have looked through the mozilla documentation but I am still a little confused of how I need to go about updating the info from the API on my webpage. </p> <p>My Javascript which includes the refresh function and the addWeather function. The refresh function is suppose to refresh the api information on my website every hour on the hour(which makes use of the xmlhttprequest that i need help on). addWeather function adds the API information to the html and it works well indeed.</p> <p>Here is the Javascript:</p> <pre><code>window.onload = init; function init() { //populate the weather addWeather(); //refresh the page every hour setInterval(refreshPage(), 3600000); } //refresh the page information every hour function refreshPage(){ //make new request to the webservice var req = new XMLHttpRequest(); req.onload = addWeather(); } //add the weather info from the weather service function addWeather(){ jQuery(document).ready(function($) { $.ajax({ url: "http://api.wunderground.com/api/6368023a57d122c7/geolookup/conditions/q/DominicanRepublic/Barahona.json", dataType : "jsonp", success : function(parsed_json) { var location = parsed_json['location']['city']; var temp = parsed_json['current_observation']['temp_c']; var weather = parsed_json['current_observation']['weather']; var humid = parsed_json['current_observation']['relative_humidity']; var wind_direction = parsed_json['current_observation']['wind_dir']; var wind_speed = parsed_json['current_observation']['wind_kph']; var wind_string = wind_direction + " " + wind_speed + " Km/h"; document.getElementById("weather").innerHTML = "Weather " + weather; document.getElementById("temp").innerHTML = "Tempurature " + temp + "°C"; document.getElementById("hum").innerHTML = "Humidity " + humid; document.getElementById("wind").innerHTML = "Wind " + wind_string; } }); }); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload