Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3600328
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:28:52+00:00 2026-05-18T20:28:52+00:00

I have made an API call with the help of $.getJSON but I don’t

  • 0

I have made an API call with the help of $.getJSON but I don’t know how do I make the returned data available globally to be used in other functions as well.

The return in below code doesn’t work but instead if I alert it: it works charms.

$.getJSON(url, function(timeInfo){
        return timeInfo.time;
});

Also out of 2010-12-09 12:53 time format. How do I take the 12 (the hour) out.

Please help and sorry for including two questions in one.

Detailed code:

function handle_geolocation_query(position) {
    if(position[0] == 'Yes'){
        var url = "http://ws.geonames.org/findNearByWeatherJSON?lat=" + position[1] + "&lng=" + position[2] + "&callback=?";
    } else {
        var url = "http://ws.geonames.org/findNearByWeatherJSON?lat=" + position.coords.latitude + "&lng=" + position.coords.longitude + "&callback=?";
    }
    $.getJSON(url, function(weatherInfo){
        var clouds = weatherInfo.weatherObservation.clouds;
        var weather = weatherInfo.weatherObservation.weatherCondition;
        var time = getTimeInfo(position);
        if(time.getHours()>=6 && time.getHours()<=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] + "&lng=" + position[2] + "&callback=?";
    } else {
        var url = "http://ws.geonames.org/timezoneJSON?lat=" + position.coords.latitude + "&lng=" + position.coords.longitude + "&callback=?";
    }
    $.getJSON(url, function(timeInfo){
        return timeInfo.time;
    });
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T20:28:53+00:00Added an answer on May 18, 2026 at 8:28 pm

    You can pass the data to other functions and objects from the success callback function in $.getJSON(). The way you do that is either create a global object or function:

    var MYWEBSITE = { data: {} };
    var myGlobalFunction = function(data) { 
      alert("The time I got is: " + data.time);
    };
    
    $.getJSON(url, function(timeInfo) {
    
      // set the data property on MYWEBSITE
      MYWEBSITE.data = timeInfo;
    
      // execute the function and pass the parameter
      myGlobalFunction(timeInfo);
    });
    

    EDIT: Added example of passing global functions as second parameter

    You can also pass a global function as second parameter:

    var globalFunction = function(data) { ... };
    
    $.getJSON(url, globalFunction);
    

    That way, globalFunction gets passed whatever is returned in the response.

    EDIT 2: Added regular expression example for time extraction

    To extract the hour portion of the date, you can use a Regex to match the components:

    var time = "2010-12-09 12:53", hour = "";
    var timeMatcher = /^([0-9]{4}-[0-9]{2}-[0-9]{2})\s([0-9]{2}):([0-9]{2})$/;
    if(timeMatcher.test(time)) {
      hour = timeMatcher.match(time)[2]; // finds the second brace, hour should contain "12"
    }
    

    For more info, see http://en.wikipedia.org/wiki/Regular_expression

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made an API call with the help of $.getJSON but I don't
i am using your api and i have made a success call to upload
I have made my own map using the google maps api. It is a
I have made a code that read data from flash Nand (without filesystem). fd
I have made a cart and the cart has remove item button, but the
I have some code that requests some JSON from an API. When data is
I have been looking around the Twitter api without much luck. Does anyone know
I have an API for analysing my exercise data (which I scrape runkeeper 's
I have created a TV parameter representing a DropDownList Menu. But when I call
i like to preform simple facebook api call via http rest but whiteout using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.