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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:39:26+00:00 2026-06-01T20:39:26+00:00

I know questions about loading XML into a JS variable have been posted here

  • 0

I know questions about loading XML into a JS variable have been posted here many times, but I didn’t find a solution that would work. In my script I declare a variable before an ajax request, and then add the result to the variable. This works only if I add alert to the script:

var myDB;
$.ajax({
    type: 'GET',
    url: 'db.xml',
    dataType: 'xml',
    success: function (xml){
        myDB = xml;
    }
});

alert(myDB); //returns: undefined

$(myDB).find('item').each(function (){
    var question = $(this).find('question').text();
    alert(question);
});

The above code works only with the alert. When I delete the alert, the code doesn’t work. How can I make this work without the alert?

  • 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-01T20:39:27+00:00Added an answer on June 1, 2026 at 8:39 pm

    An ajax request is asynchronous. That means, the function you gave in the success option is excuted somwhen later.

    After you’ve started the request, you’re variable is still empty. Only if you wait long enough to confirm the blocking alert, the variable will have been loaded.

    You will need to add the iteration to the success function, where the xml data is certainly available.

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

Sidebar

Related Questions

I know similar questions have been asked, but I'm not sure about the answers
Alright, I know questions like this have probably been asked dozens of times, but
I know there have been some questions about this, but I can't seem to
I know there's a lot of questions about this but I've been struggling with
NOTE: I know there are many questions that talked about that but I'm still
I know they are many questions about Silverlight vs HTML5.(ex: Which is the future
I know that there are many different questions about this sort of topic on
I know that their are questions and articles about WCF deployment, but i don't
I know there are a lot of questions about aligning Facebook buttons but they
i know there are several questions about regex recursion in .net. I can write

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.