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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:49:00+00:00 2026-06-09T00:49:00+00:00

Long story short, I’m trying to store corresponding data values from a JSON returning

  • 0

Long story short, I’m trying to store corresponding data values from a JSON returning AJAX into these global arrays. I know that the arrays are constructing correctly because I’ve put alerts within AJAX, but when I put it outside the AJAX, the array is still undefined.

How can I export either the entire popData JSON object to work on it and store the values in the global arrays or get the populating of the arrays in the AJAX to carry outside the call? I need these arrays to be accessible by another function to compare the population values to a narrow range of values selected by the user–if anyone wants to suggest a better way of doing this, but it has to pull the population values onLoad which is already done in the HTML. I think this is the most streamlined way to do that with the fewest AJAX calls on the server, but I’m open to suggestions! 😀

    var popProducers = new Array();
    var popProducersCount = new Array();


    function getPopulationInfo(){

        $.ajax({
            url:phpURL,
            cache:false,
            dataType:"json",
            data: { },
            success:function(popData){

                for (i=0;i<popData.length;i++){

                    //producers and producersCount should be the same length at all times!
                    //If current producer name isn't in array already
                    if(popProducers.indexOf(popData[i].ProducerName) == -1){
                        //add new element to represent new producer quantity (producerCount.length returns number of elements in the array, thus if there are no elements = 0 thus making index 0 equal to 1 and so on)
                        popProducersCount[popProducersCount.length] = 1;
                        //Adds the producer name to the list of producers
                        popProducers[popProducers.length] = popData[i].ProducerName;
                    } else {
                        //Otherwise, it will increment the index of the producersCount array corresponding with the pre-existing producer name's index by 1
                        popProducersCount[popProducers.indexOf(popData[i].ProducerName)] += 1;
                    }


                }

            }
        });

        alert("Population Data Alert: " + popProducers);
  • 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-09T00:49:02+00:00Added an answer on June 9, 2026 at 12:49 am

    .ajax() and its underlaying XMLHttpRequest() create asyncronous requestes by default. That just means, your alert() statement is encountered before your success handler.

    Easy solution here, move that alert() into the success handler at the very bottom.

    If you want to deal with it in a more apropriate way, you could use jQuerys Deferred objects in a way like

    function getPopulationInfo(){
        return $.ajax({
           // lots of stuff
        });
     }
    

    and then call it like

    getPopulationInfo().done(function() {
        alert("Population Data Alert: " + popProducers);
    });
    

    by returning the .ajax() method we implcitly return a Deferred object. Long story short, you can pass in some additional callbacks for success (.done()), error (.fail()) and complete (.always())

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

Sidebar

Related Questions

Long story short: on Chrome and Safari only, values from a login form are
Long story short, I have an ASP.NET application I'm trying to debug and at
So long story short, im trying to build a chat application....well its already built
Long story short I am trying to replicate the Sleeping barber problem in Erlang.
Long story short, I'm using a buggy WordPress template and we're too far into
Long story short, here's what i'm going to be trying to do: There is
Long story short: I have 2 collections of objects. One contains good values (Let's
Long story short, I ended up deleting the root user from PHPMyAdmin in EasyPHP.
Long story short: We've got a system that we're moving from one server to
I'm trying to create a simple animation. Long story short, I've got a list

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.