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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:13:21+00:00 2026-06-12T11:13:21+00:00

function getData(jsonAddress) { var data = new Array(); var xhr = $.getJSON(jsonAddress, function(meas) {

  • 0
    function getData(jsonAddress) {
      var data = new Array();
      var xhr = $.getJSON(jsonAddress, function(meas) {
        for (var i = 0; i < meas.length ; i++) {
          var dt = datetimeSplitter(meas[i].valuedate);
          data[i] = [Date.UTC(dt[0],dt[1]-1,dt[2],dt[3],dt[4],dt[5]),parseInt(meas[i].value,10)];
        };
      });
      alert(data);
    }

I would like to make the variable “data” available to the function getData so I can return it (in this case alert). I understood it is a problem of scope, and can be solved with closure. I understood also what is a closure, but definitely don’t know the syntax for this specific case.

  • 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-06-12T11:13:22+00:00Added an answer on June 12, 2026 at 11:13 am

    It’s not a problem of scope, it’s a problem of asynchronous callbacks.

    You need to pass in a callback function to this method, in order to get the response of your getJSON() call.

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

Sidebar

Related Questions

function getData(d){ Back = new Object(); $.getJSON('../do.php?', function(response){ if(response.type == 'success'){ Back = {
GET_DATA() GET_DATA() contains this: var xhr; ... function get_data( phrase ) { xhr =
function GetDaysInMonth(month, year) { return 32 - new Date(year, month, 32).getDate(); } Ok, I
function checkuser(user) { var ret = false; $.ajax({ type:'POST', url:'user.php', async:false, data:{'user':user}, success:function (data)
var Model= function () { function GetData() { // Sending the request and i
I have a function getData(void* data) which should copy to data some internal calculated
I have this code: ... function init() { getdata(); } var txt; function getdata()
I has something like this: <div id=content></div> and JS: function getData(id) { $.getJSON('url/to/jsondata',{id: id},
I am using ajax to get data from a php file function getdata(param) {
Public Shared Function GetData(ByVal id As Integer) As List(Of SomeClass) Dim command As New

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.