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

  • Home
  • SEARCH
  • 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 7869727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:24:56+00:00 2026-06-03T01:24:56+00:00

Any insight into the problem here? When run, the code yields nothing. No text

  • 0

Any insight into the problem here? When run, the code yields nothing. No text appears on the page. If I uncomment the commented line, the xml results appear. Why can’t I pass it as a variable? (I do get the alert, fyi, so the function is being called.)

 <script type="text/javascript">
           function loadXMLDoc(parameterString)
               {
                   alert("loadXMLDoc has been called.");
                   var xmlhttp = new XMLHttpRequest();

                   xmlhttp.onreadystatechange=function()
                   {
                       if (xmlhttp.readyState==4 && xmlhttp.status==200)
                       {

                  //document.getElementById("xmlResults").innerHTML = xmlhttp.responseText;
                               alert("Got the response!");
                               return xmlhttp.responseText;
                           }
                           else document.getElementById("xmlResults").innerHTML = "No results."
                       }

                       var url =  "http://metpetdb.rpi.edu/metpetwebsearchIPhone.svc?" + parameterString;
                   xmlhttp.open("GET",url,true);
                   xmlhttp.send();
               }
        </script>



        <script type="text/javascript">

       $(function(){

        //left out irrelevant code which creates the var "parameters"

         var results = loadXMLDoc(parameters);

         document.getElementById("xmlresults").innerHTML = results;

       });


       </script>


<body>
<div id="xmlResults"></div>
</body>
  • 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-03T01:24:57+00:00Added an answer on June 3, 2026 at 1:24 am

    By definition, an asynchronous call performs the real work without making the caller wait for the result. You do need to use a callback function, for example:

    <script type="text/javascript">
      function loadXMLDoc(parameterString, onComplete, onError) {
        alert("loadXMLDoc has been called.");
        var xmlhttp = new XMLHttpRequest();
    
        xmlhttp.onreadystatechange=function() {
          if (xmlhttp.readyState==4) {
            if(xmlhttp.status==200) {
              //document.getElementById("xmlResults").innerHTML = xmlhttp.responseText;
              alert("Got the response!");
              onComplete(xmlhttp.responseText);
            } else {
              onError();
            }
          }
        };
    
        var url =  "http://metpetdb.rpi.edu/metpetwebsearchIPhone.svc?" + parameterString;
        xmlhttp.open("GET",url,true);
        xmlhttp.send();
      }
    </script>
    
    <script type="text/javascript">
      $(function(){
        //left out irrelevant code which creates the var "parameters"
        loadXMLDoc(parameters, function(results) {
          // this function will be called if the xmlhttprequest received a result
          document.getElementById("xmlresults").innerHTML = results;
        }, function() {
          // this function will be called if xhr failed
          document.getElementById("xmlResults").innerHTML = "No results.";
        });
      });
    </script>
    

    By the way, since you are already using jQuery, you should just use its builtin AJAX functionality instead of building your custom xmlhttprequest.

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

Sidebar

Related Questions

I've run into issues with banding of my PNG files. Digging into the problem
Apologies for the vague title, here's my problem: The goal of my code is
Does anyone has any insight on organizing sqlalchemy based projects? I have many tables
Any idea why the LINQ OrderBy is not working in following code, (have no
Any ideas how I can fix this? Line 58, Column 72: Bad value fancybox2
Okay, here is my problem: I have a form that requires to have two
Hey all, really bashing my head against a keyboard here, any information or pointing
ggplot2: Why Does Semi-Transparency + pdflatex Cause Heavier-Than-Normal PDF Fonts? I've run into a
I've been looking around everywhere and haven't gotten a concrete answer. Here's the problem:
I shouldn't say I actually have a problem (the code seems to... work? Although

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.