Results 1 to 2 of 2

Thread: Ajax XMLHTTPRequest Issue

  1. #1
    Join Date
    Mar 2011
    Posts
    3

    Ajax XMLHTTPRequest Issue

    I'm trying to access an XML file on an external server:
    'http://www.exactscores.com/SoccerLivescoreXml.xml'

    I'd like to be able to access info inside the XML tags and place the data on my website in a creative manner. I've come up with some code to grab the data, but it is sent as a text file, not an xml. Is there some code I can use to access the xml data by referencing the tags, or to download the file and save it temporarily on my server as an xml file?

    Here's the code I've used so far:

    <html>
    <head>
    <script type="text/javascript">
    function loadXMLDoc()
    {
    var xmlhttp;
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function()
    {
    if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
    }
    }
    xmlhttp.open("GET","http://www.exactscores.com/SoccerLivescoreXml.xml",true);
    xmlhttp.send();
    }
    </script>
    </head>
    <body>

    <h2>Scores</h2>
    <button type="button" onclick="loadXMLDoc()">Request data</button>
    <div id="myDiv"></div>

    </body>
    </html>

  2. #2
    Join Date
    Mar 2011
    Posts
    38
    Hello Friend,

    Just use this block.
    xmlhttp.onreadystatechange=function()
    {
    if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("myDiv").innerHTML=xmlhttp.responseXML;
    }
    }


    Ahamed

Similar Threads

  1. AJAX/ Javascript Issue
    By WBJ in forum Client & Server Side Scripting (PHP, ASP, JavaScript)
    Replies: 0
    Last Post: 10 Feb 2010, 11:29 AM
  2. IE7 issue? Or server issue? Or javascript? Very odd!
    By db777 in forum Client & Server Side Scripting (PHP, ASP, JavaScript)
    Replies: 1
    Last Post: 20 Apr 2009, 10:14 PM

Posting Permissions

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