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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:00:42+00:00 2026-05-22T12:00:42+00:00

OK, so I cannot seem to be able to change the global variable of

  • 0

OK, so I cannot seem to be able to change the global variable of systemPath after it goes through the ajax.It will work inside of ajax, but I need that updated variable outside of ajax. basically I’m trying to create an array of paths from xml and use them to locate other xml files that I can generate a table from.

Does anyone know what’s going on here? Does ajax run before the variable is set and that is why I get an array length of 0 after the ajax?

    var systemPath = new Array();
var techDigestArr = new Array();
var addToArray = function(thisarray, toPush){
    thisarray.push(toPush);
}

$.ajax({
    url: fullPath+"technical/systems/systems.xml",
    dataType: ($.browser.msie) ? "text" : "xml",
    success: function(data){
                            var xml;    
                            if (typeof data == "string") {
                               xml = new ActiveXObject("Microsoft.XMLDOM");
                               xml.async = false;
                               xml.loadXML(data);
                            } else {
                               xml = data;
                            }
                            $(xml).find("system").each(function(){
                                var urlString = fullPath + "technical/system_" + $(this).attr("id") + "/" + $(this).attr("id") + "tech-digest.xml <br />";
                                //alert(urlString);
                            $("#td-articles").append(systemPath.length + urlString);
                                addToArray(systemPath,urlString);
                                //systemPath.push(urlString);
                            });
                        $("#msg-output").append("total - " +systemPath.length);//Returns 48

                    },//END SUCCSESS
    error: function(){
        alert("Sorry - ");
        history.go(-1);
    }
});//END AJAX CALL
    $(document).ready(function(){
        //$("#msg-output").append("total - " + systemPath.length); Returns 0
    });
  • 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-22T12:00:43+00:00Added an answer on May 22, 2026 at 12:00 pm

    The ajax is ran asynchronously. Things execute in this order in your code.

    1. stuff before $.ajax()
    2. $.ajax() initiates an ajax call (while waiting for the response it continues to run the rest of the code)
    3. stuff after $.ajax()
    4. success callback

    Note that depending on how fast the call is 3 and 4 might occur in reverse order (not the case here)

    So when $(document).ready() is executed the ajax call might not have returned yet, so the code in the success callback didn’t have a chance to execute. If you are lucky and have a fast connection than maybe the response will come before document ready, but it’s unlikely.

    Just so you can see that the global variable gets updated you can set a timeout:

    $(document).ready(function(){
      setTimeout(function(){
        $("#msg-output").append("total - " + systemPath.length);
        //if the delay set below is more than the time between the ajax request and the server response than this will print the correct value 
      },2000);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this may be basic but I cannot seem to add a member
I have a question that might seem basic but I just cannot figure out
This should be easy although I cannot seem able to find it somewhere. myabe
I apologize if this question has been answered already, but I cannot seem to
I've been trying to crack this nut for a while but I cannot seem
I have been looking thoroughly through the Web and I cannot seem to find
I cannot seem to debug my JavaScript code with Firebug. The play button is
I cannot seem to access the context object using a loop context is set:
I cannot seem to compile mod_dontdothat on Windows. Has anybody managed to achieve this?
I cannot seem to figure out I am getting the following error in IE

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.