
April 13th, 2012, 03:30 AM
|
|
Registered User
|
|
Join Date: Apr 2012
Posts: 3
Time spent in forums: 55 m 6 sec
Reputation Power: 0
|
|
|
Trouble with accessing online XML
Hi everyone, I am trying to access an online XML file, for example: http://www.rgraph.net/sample.xml using HTML.
Code:
<html>
<body>
<script type="text/javascript">
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
var url = "http://www.rgraph.net/sample.xml";
xmlhttp.open("GET",url,false); //If url is replaced by the downloaded file named "sample.xml" this works and give the output of 1.
// but works only on Mozilla
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
var x=xmlDoc.getElementsByTagName("stats");
alert(x.length);
</script>
</body>
</html>
Any comment or advice would be much appreciated!
PS: Why does this only work on Mozilla and NOT on Safari or Chrome?
Many thanks!
|