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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:37:07+00:00 2026-05-15T17:37:07+00:00

I have simple JavaScript code that is using the Ajax API for fetching a

  • 0

I have simple JavaScript code that is using the Ajax API for fetching a XML from the server.

function loadXML(path, node) {
    var response_obj = "";
    /* Fire Ajax request and get the XML */
    var request_obj = "";
    $.ajax({
        async: true,
        type: "GET",
        url: path,
        dataType: "xml",
        success: function(XMLObj, status, resquestObj) {
            response_obj = XMLObj;
            request_obj = requestObj;
        },
        error: function(){
            alert("Unable to fire AJAX request");
        }
    });
    alert(response_obj); //<-- This is NULL if async=true
   /* More logic to follow which will use response_obj (XML)
      and render it in the 'node' argument passed. */
}

Where, the path corresponds to a valid XML (tested using W3C validator) and the node points to a DIV element on the HTML page where the response has to be parsed and appended.

What I need is that the Ajax call should return me the responseXML object which I will parse and render. For that, I am assigning the response XML to a local variable (local to this function’s scope) and then would use it (currently I just send it to alert).

Now, the problem is that when I use this function with async set to false, the alert call successfully returns [object XMLDocument]. But as soon as I change async to true, null is printed by alert.

What I understand is that when async:true, the last alert is called even before the XML is returned by the Ajax call. Similarly, when async:false, this is a serialized call and when control reaches the last alert call, the XML has already arrived.

What should I do so that:

  1. I have the response Object (and
    request object) as returned by the Ajax
    call in the local variables so that
    I can use them. I understand that
    the call back function, if passed to
    success, would have three
    parameters – but, I don’t know how
    to return from that call back
    function into my loadXML function.
  2. That I don’t have to convert the Ajax call into sync because this is just one of the functions that I am firing – there are many other Ajax calls which too are to be issued.
  3. Am I correct in my assumption that async:false is serialized in this function whereas async:true is not?
  • 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-15T17:37:07+00:00Added an answer on May 15, 2026 at 5:37 pm

    yes, what you have mentioned about async:true is correct. So it’s natural that alert() will fail if async is true and if async is false it will work.

    You should put the alert() in the success callback.

    Or you can also make a function say ajaxSuccess and call it in success Callback().
    Put the alert() in that ajaxSuccess function.

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

Sidebar

Ask A Question

Stats

  • Questions 448k
  • Answers 448k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You should use refresh:false paremeer of the navigator (see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:navigator):… May 15, 2026 at 7:59 pm
  • Editorial Team
    Editorial Team added an answer Yes, there is one. You have to use the DataImportHandler… May 15, 2026 at 7:59 pm
  • Editorial Team
    Editorial Team added an answer A .htaccess file has effect only in/on : The directory… May 15, 2026 at 7:59 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.