I'm trying to learn javascript at the moment, but am having a problem with XmlHttpRequest.
Hopefully someone can help me out with this one, the following code works on my PC using Opera/9.24 (Windows NT 6.0; U; en) (and other browsers), but not on the Wii.
On the Wii, it will alert "file found" (see line57 of the code), so I guess it must create the object okay, but it does not alert the responseText on the following line. Nor does it alert an error message. I did some googling, but couldn't see anything about the Wii not supporting responseText and I'm pretty sure responseText is used in google maps which work on the Wii.
So, it's probably something wrong with my code. If anyone can help with this it would be greatly appreciated!
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
<script type="text/javascript">
function createXmlHttpRequest()
{
if (window.XMLHttpRequest)
{
var oHttp = new XMLHttpRequest();
return oHttp;
}
//IE5 & 6
else if (window.ActiveXObject)
{
try
{
var oHttp = new ActiveXObject("MSXML2.XmlHttp.6.0");
return oHttp;
}
catch(error)
{
try
{
var oHttp = new ActiveXObject("MSXML2.XmlHttp.3.0");
return oHttp;
}
catch(error)
{return null;}
}
}
}
</script>
</head>
<body>
<script type="text/javascript">
var myAJAX = createXmlHttpRequest();
myAJAX.open("GET", "text.txt", true);
myAJAX.onreadystatechange = readyStateChange;
myAJAX.send(null);
function readyStateChange()
{
if(myAJAX.readyState == 4)
{
//Object fully loaded & requested data received
if(myAJAX.status == 200)
{
try
{alert("file found");
alert(myAJAX.responseText);}
catch(error)
{alert(error);}
}
else if (myAJAX.status == 404)
{alert("file not found");}
else
{alert("an error occurred, Error code="+myAJAX.status);}
}
}
</script>
</body>
</html>