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 6249801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:18:20+00:00 2026-05-24T13:18:20+00:00

What I want is for data retrieved from one function to be displayed in

  • 0

What I want is for data retrieved from one function to be displayed in another . I was told that using a global variable would allow me to accomplish this What is the best way to store a value for use in a later function? I'm hearing global variables are evil.

Here is what I tried. http://jsfiddle.net/8j947/17/

When I try to display the global variable as an alert it comes back as undefined (which might not be viewable on jsfiddle). I’m thinking this is because the data isn’t actually getting stored, but I’ve only been coding for 3 weeks, so what do I know. If you guys could help me out by showing me what I did wrong or proposing an alternate solution that would be great.

  • 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-24T13:18:22+00:00Added an answer on May 24, 2026 at 1:18 pm

    Your alert function at the bottom is executing immediately after getCrossDomainJson is called, and before the callback function passed into getCrossDomainJson is called. Since the someProperty property is set inside the callback function, when you refer to it in the alert, it hasn’t actually been set yet.

    Give your alert function a name and call it somewhere else AFTER the callback function completes.

    function getCrossDomainJson(url, callback) {
        $.ajax({
            url: "http://query.yahooapis.com/v1/public/yql?callback=?",
            data: {
                q: 'select * from xml where url="' + url + '"',
                format: "json"
            },
            dataType: "jsonp",
            success: callback
        });
    }
    
    var MyStatus = {};
    getCrossDomainJson("http://xdiscgolfplanetx.channel-api.livestream-api.com/2.0/getstream", function(data) {
        // data is in JSON format:
        console.dir(data);
        if (data && data.query && data.query.results && data.query.results.channel) {
            var isLive = (data.query.results.channel.isLive);
            MyStatus.someProperty = data.query.results.channel.isLive;
        // alert (isLive)
            if (isLive == 'true') {
                alert ('working')
            }
            alertSomeProperty();            // now that the someProperty property has been set and MyStatus 
                                            //is global, you'll see that you can refer to it even outside of this block
        }
    });
    
    function alertSomeProperty(){
        alert (MyStatus.someProperty)
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to port data from one server's database to another server's database. The
I want to generate some formatted output of data retrieved from an MS-Access database
I want a data structure that will allow querying how many items in last
I am having trouble passing data retrieved from a $.post() function to use in
I have DropDownList with CascadingDropDown extender. If I want to retrieve data from the
I have a scripts that retrieves huge data on a table. I want to
I want sync data from iphone to the webs server. My question is how
I'm trying to produce a line chart using Flot, but I want the data
I have two XML sources to retrieve data from. I want to use them
I'm trying to create a windows form application that manipulates data from several tables

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.