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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:15:56+00:00 2026-06-04T08:15:56+00:00

I have this function: function getReport(name,x) { var xArr = []; var yArr =

  • 0

I have this function:

function getReport(name,x) {
    var xArr = [];
    var yArr = [];
    $.ajax({
        async: false,
        type: "POST",
        //async: false,
        //dataType: "json",
        url: "reportAjax.php",
        data: "name="+ name,
        success: function(data){
            var json = $.parseJSON(data);
            var chartDesc = json.INFO.DESC;
            $.each(json.RESULT, function(i, object) {
                $.each(object, function(property, value) {
                    //alert(property + "=" + value);
                    if (property == x) {
                        xArr.push(value);
                    }
                    else {
                        yArr.push(parseInt(value));
                    }

                });
            });                
        }
    }); 
    console.log(xArr);
    console.log(yArr);
    console.log(chartDesc);
    drawChart(xArr,yArr,chartDesc);
}

For some reason, I can see in the console.log the values of xArr and yArr, but I get chartDesc is not defined for chartDesc.

If I move the console.log(chartDesc) line to be under this line var chartDesc = json.INFO.DESC I can see it properly.

Why is that?

  • 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-04T08:15:58+00:00Added an answer on June 4, 2026 at 8:15 am

    You are declaring the chartDesc variable inside the AJAX callback function, so it is outside the scope of your later reference to it.

    To fix this, remove the var from the start of the line, and instead declare it at the top of the function with the xArr and yArr variables:

    var xArr = [];
    var yArr = [];
    var chartDesc = "";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this function: public static void Play(string FileName, bool Async = false) {
I have this function written: <script type="text/javascript"> function getStartDate(value) { $.post("gSearch.php", {dateSearch:value}, function(data){ $('#results').html(data);
I have this function: public bool IsValidProduct(int productTypeId) { bool isValid = false; if
I have this function: function Connect($url, $post = 0, $postfields = '') { $ch
I have this function function smth() { var container = null; var newContainer =
I have this function from a plugin (from a previous post) // This method
I have this function $.ajax({ url: aurl, method: 'GET', beforeSend: function (req) { req.setRequestHeader('Authorization',
I have this function that runs over returned json data. It is really fast
I have this function: function disableDiv(divId, action){ var divId = byId(divId); if(action==true){ divId.style.display='none'; }
I have this function (defun mention-notify (match-type nickuserhost msg) (interactive) (if (and (eq match-type

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.