I want to dynamically load txt via XMLHttpRequest, but I can't seem to get the code to work with an onload event handler. please! help me gurus!
here is some code!
html
<!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"> <head> <title>Plaid Apple Studios</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <link href="/css/main.css" rel="stylesheet" type="text/css" /> <script src="/js/main.js" language="javascript" type="text/javascript"> loadXMLDoc(); </script> </head> <body class="background"> <!-- Not Content --> <!-- Content --> <div id="main" align="center"><h1>Plaid Apple Studios</h1></div> <div id="nav">Home</div> <div id="content"></div> </body> </html>javascript
//main load script
function loadXMLDoc()
{
alert("Sent");
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("content").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","/txt/content.txt",true);
xmlhttp.send();
}
Edited by Injury, 10 February 2011 - 10:04 PM.


Sign In
Create Account


Back to top









