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

  • Home
  • SEARCH
  • 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 6206031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:22:37+00:00 2026-05-24T05:22:37+00:00

I have a program. $(document).ready(function(){ var tmpArray = []; var x; var y; $.plot($(#chart),

  • 0

I have a program.

$(document).ready(function(){
    var tmpArray = [];
    var x;
    var y;
    $.plot($("#chart"), [ tmpArray]);   
    $.getJSON("111.json", function(data) {
        var i = 0, dataSize = data.length;
        for(i; i < dataSize; i++){
            var x = parseFloat(data[i].Time.substring(0, data[i].Time.length -2).replace(/:/g, ""));
            var y = parseFloat(data[i].Bid) ;
            tmpArray.push ( [x,y]);
        }           
    //$.plot($("#chart"), [ tmpArray]); 
    });
    $.plot($("#chart"), [tmpArray]);    
});

Actually, when “$.plot($(“#chart”), [tmpArray]);” inside getJSON(), it works well. But, when I put it outside getJSON() it won’t work. But if I put a breakpoint there and stepover it, it works. Could someone tell me why? Put inside works well in web brower but android. It works on android but only inside getJSON() function.

  • 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-24T05:22:37+00:00Added an answer on May 24, 2026 at 5:22 am

    Since you are making an asynchronous call to get the data, in order to use it you have to put the code that uses it in the callback for the async call.

    Meaning, $.getJSON("111.json" starts a ‘thread’ that goes to the server and retrieves the values from 111.json. but the normal ‘thread’ continues on with the line $.plot($("#chart"), [tmpArray]); without waiting on the async call to finish (which is essentially the definition of async).

    Therefore, you have to put $.plot($("#chart"), [tmpArray]); inside of the function(data {}), because that is a callback that fires after the async call is finished.

    And one more thing…the reasons you putting a breakpoint there works is because you are essentially letting the async call finish (since it probably returns in sub second), and THEN running the $.plot($("#chart"), [tmpArray]);…which gives the illusion that it should work without the debugger getting in the way.

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

Sidebar

Related Questions

In background.html of my chrome extension I have: $(document).ready(function(){ var some_variable = some_variable; function
I have the following jquery code: $(document).ready(function() { $(#build_table, a.coursename, .Start Date, .Book Title,
So I have a Colorbox setup for the document.ready function: $(document).ready(function () { $('#btnMyButton').colorbox({
I have a program that reads an XML document from a socket. I have
I have program that has a variable that should never change. However, somehow, it
I have program, that must interact with a console program before my program can
I have program that runs fast enough. I want to see the number of
I have a program that spits out both standard error and standard out, and
I have a program that creates a Windows user account using the NetUserAdd() API
I have a program that uses the mt19937 random number generator from boost::random. I

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.