Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>remove () from set interval. now you're passing returned value by addWeather and you wan to pass function itself. So: </p> <pre><code> setInterval(addWeather,3600000) </code></pre> <p>If you're requesting data with XHR it's available as this.responseText. if it's JSON you can parse it with </p> <pre><code> var r = JSON.parse(this.responseText) </code></pre> <p>inside add weather function, and it's not like that. Proper XHR:</p> <pre><code> var r = new XMLHttpRequest(); r.open('GET','your_url_here'); r.onload = addWeather; r.send() </code></pre> <p>again without (). putting () at the end of function executes it and uses returned value, giving just name will asign function itself, and you want to make variable r.onload equal to your function. Because xhr checks onload property and executes it if its a function</p> <p>after this you don't need jQuery ajax as its just API for XHR and you have already created request, now read value using responseText. So:</p> <p>fix XHR, remove jQajax and put content of given to jQajax function into addWeather., so addWeather would look like:</p> <pre><code> function addWeather(){ var parsed_json=JSON.parse(this.responseText); var location = parsed_json['location']['city']; ... rest of this internal function ... </code></pre> <p>also remember that parsed JSON will be an object so you can use </p> <p>var location = parsed_json.location.city;</p> <p>it should be faster</p> <p>ah, and change addWeather(); in first line (this before set interval) to refreshPage(); as addWeather(); will now crash as it would be executed manually so there wouldn't be <code>this.responseText</code> variable (as it'd be called "outside" xhr)</p>
    singulars
    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