PDA

View Full Version : Ajax XMLHTTPRequest Issue



inplaytoday
28 Mar 2011, 04:20 PM
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>

awniyya1
04 Apr 2011, 02:56 AM
Hello Friend,

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


Ahamed