Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I make jQuery JSON returned data available globally & Minor string parse help?
    primarykey
    data
    text
    <p>I have made an API call with the help of <code>$.getJSON</code> but I don't know how do I make the returned data available globally to be used in other functions as well.</p> <p>The <code>return</code> in below code doesn't work but instead if I <code>alert</code> it: it works charms.</p> <pre><code>$.getJSON(url, function(timeInfo){ return timeInfo.time; }); </code></pre> <p><strong>Also out of 2010-12-09 12:53 time format. How do I take the 12 (the hour) out.</strong></p> <p>Please help and sorry for including two questions in one.</p> <p>Detailed code:</p> <pre><code>function handle_geolocation_query(position) { if(position[0] == 'Yes'){ var url = "http://ws.geonames.org/findNearByWeatherJSON?lat=" + position[1] + "&amp;lng=" + position[2] + "&amp;callback=?"; } else { var url = "http://ws.geonames.org/findNearByWeatherJSON?lat=" + position.coords.latitude + "&amp;lng=" + position.coords.longitude + "&amp;callback=?"; } $.getJSON(url, function(weatherInfo){ var clouds = weatherInfo.weatherObservation.clouds; var weather = weatherInfo.weatherObservation.weatherCondition; var time = getTimeInfo(position); if(time.getHours()&gt;=6 &amp;&amp; time.getHours()&lt;=18){ var weatherClass = placeImageDay(clouds, weather); $('#weatherImage').show().addClass(weatherClass); } else { var weatherClass = placeImageNight(clouds, weather); $('#weatherImage').show().addClass(weatherClass); } }); } function getTimeInfo(position){ if(position[0] == 'Yes'){ var url = "http://ws.geonames.org/timezoneJSON?lat=" + position[1] + "&amp;lng=" + position[2] + "&amp;callback=?"; } else { var url = "http://ws.geonames.org/timezoneJSON?lat=" + position.coords.latitude + "&amp;lng=" + position.coords.longitude + "&amp;callback=?"; } $.getJSON(url, function(timeInfo){ return timeInfo.time; }); } </code></pre>
    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