CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2011
    Posts
    1

    AJAX question/issue

    I am new to AJAX and am trying to write my first AJAX program. I am trying to reach out and connect with a server. I "should" be getting some XML data sent back to me but my responseXML remains null. Below is the code I am using and I will also print out what I am hoping to get back. I am able to create the XMLHttpRequest and my readyState does reach 4. My status is 0 but I expected that.

    The code (and I have included some document.writes just to help me debug) is:
    Code:
    <html>
    <head>
    <script type="text/javascript">
    function loadXMLDoc()
    {
    document.write(" In function");
    var xmlhttp;
    if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
      document.write(" created request ");
      }
    else
      {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    
    xmlhttp.onreadystatechange=function()
      {
      if (xmlhttp.readyState==4)
        {
        document.write(xmlhttp.responseText);
        }
      }
    xmlhttp.open("GET","http://localhost:8080/vlrestapi/v1.0/system",true);
    xmlhttp.send();
    }
    </script>
    </head>
    <body>
    
    <h2>AJAX</h2>
    <button type="button" onclick="loadXMLDoc()">Request data</button>
    
    </body>
    </html>
    When I put the "http://localhost:8080/vlrestapi/v1.0/system" into a browser, this is what I get back and what I hope to pull back with my AJAX program but it is not happening:

    Code:
    <?xml version="1.0" encoding="UTF-8" ?> 
    - <VLResponse>
      <content class="string">VisuaLinks REST API | Host: nb-lhunt/192.168.183.1 | Time: Wed Feb 09 14:38:56 EST 2011</content> 
      </VLResponse>
    Any help anyone could give me would be greatly appreciated.

    Thank you
    Last edited by PeejAvery; February 9th, 2011 at 09:30 PM. Reason: Added code tags

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: AJAX question/issue

    Make sure the status returns 200 before grabbing the responseText or responseXML.

    http://www.w3schools.com/ajax/ajax_aspphp.asp
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured