Hi,
I have a php function that does some "work", it takes around 4 seconds to run and it's rather annoying having it run on page load because it delays page load, so I decided to have a little twiddly spinner that calls the php AFTER the page loads through AJAX. So, I created a file just with "lol" and then used it as the called file and it worked perfectly, spinner displayed and then the "lol" showed, so then I switched it to the PHP and it fails.
I'm assuming this is because the PHP doesn't return anything UNTIL it's all processed and the javascript calls instantly. So the 4 seconds that PHP takes to run is too long for the javascript to "wait". I took a look around and all the javascript sleeps don't seem to work properly.
How would I get this to work, which sleep/timeout function should I be using and how would I use it?
function getHTTPObject() {
if (typeof XMLHttpRequest != 'undefined') {
return new XMLHttpRequest();
}
try {
return new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
return new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
return false;
}
var http = getHTTPObject();
function handleHttpResponse() {
if (http.readyState == 4) {
var temp = http.responseText;
document.getElementById("div").innerHTML=temp;
}
}
function LoadFile(){
var url = "files.php";
http.open("GET", url, true);
http.onreadystatechange = handleHttpResponse;
http.send(null);
}