Ahlahn
01-11-2011, 05:58 PM
Hey everyone,
I'm testing the code for ajax by trying to retrieve a simple xml document. I placed both the xml file and the html file on my desktop, but it's not working. I don't think there's anything wrong with the code- I found it on w3schools and modified it to retrieve the new file I created. Please take a look.
HTML FILE
<!DOCTYPE html PUBLIC "-//W3C
//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/
xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
<title>Insert Title Here</title>
<script language="JavaScript" type="text/javascript">
<!--
function loadXMLDoc()
{
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","info.xml",true);
xmlhttp.send();
}
//-->
</script>
<style type="text/css">
</style>
</head>
<body>
<div id="myDiv"><h2>I will attempt to change this text using AJAX!</h2></div>
<button type="button" onClick="loadXMLDoc()">Change Content PLZ</button>
</body>
</html>
XML File
<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<message>Hello World!</message>
</note>
Thanks!
I'm testing the code for ajax by trying to retrieve a simple xml document. I placed both the xml file and the html file on my desktop, but it's not working. I don't think there's anything wrong with the code- I found it on w3schools and modified it to retrieve the new file I created. Please take a look.
HTML FILE
<!DOCTYPE html PUBLIC "-//W3C
//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/
xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
<title>Insert Title Here</title>
<script language="JavaScript" type="text/javascript">
<!--
function loadXMLDoc()
{
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","info.xml",true);
xmlhttp.send();
}
//-->
</script>
<style type="text/css">
</style>
</head>
<body>
<div id="myDiv"><h2>I will attempt to change this text using AJAX!</h2></div>
<button type="button" onClick="loadXMLDoc()">Change Content PLZ</button>
</body>
</html>
XML File
<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<message>Hello World!</message>
</note>
Thanks!