sooo..i'm pretty new at programming in general and i decided to make a site to learn a bit about css/java/asp which im hosting on my router (lol).
anyways...i'm making a "view code" object, which is a link that expands a box and grabs data from txt files on my server using xmlhttprequest and show it in my formatted code box. this works fine, but i'm trying to make it fancy and have a "Loading..." text with a nice animation for like 500 msecs using setTimeout AND IT'S DRIVING ME NUTS!!! I apparently don't understand all the stuff on the internet explaining this. i've tried dozens of iterations of my code but none seem to work. could someone point out where I'm going wrong? Kinda frustrating :/
thanks,
david
here are the functions:
and the code used to trigger it:
anyways...i'm making a "view code" object, which is a link that expands a box and grabs data from txt files on my server using xmlhttprequest and show it in my formatted code box. this works fine, but i'm trying to make it fancy and have a "Loading..." text with a nice animation for like 500 msecs using setTimeout AND IT'S DRIVING ME NUTS!!! I apparently don't understand all the stuff on the internet explaining this. i've tried dozens of iterations of my code but none seem to work. could someone point out where I'm going wrong? Kinda frustrating :/
thanks,
david
here are the functions:
PHP:
function toggle(txt) {
var ele = document.getElementById("toggleText");
var text = document.getElementById("displayText");
if(ele.style.display == "block") {
ele.style.display = "none";
text.innerHTML = "view";
}
else {
ele.style.display = "block";
text.innerHTML = "hide";
setTimeout(getData(txt), 500);
}
}
function getData(txt) {
var req = null;
if(window.XMLHttpRequest)
req = new XMLHttpRequest();
else if (window.ActiveXObject)
req = new ActiveXObject(Microsoft.XMLHTTP);
req.onreadystatechange = function()
{
if(req.readyState == 4)
{
if(req.status == 200)
{
document.getElementById("getCode").innerHTML="<code>" + req.responseText + "</code>";
}
}
}
req.open("GET", txt, true);
req.send(null);
}
and the code used to trigger it:
PHP:
<a id="displayText" href="javascript:toggle('data.txt');">view</a>
<div id="toggleText" style="display: none">
<p>
<div id="getCode"><code><img src="1-1.gif"/> Loading...</code></div>
</p>
</div>