Jump to content

[SOLVED] Multiple readystate


XpertWorlock

Recommended Posts

I got a PHP script that before it loads, I want it to have a loading screen (cause it takes a second to load)

 

xmlHttp.onreadystatechange=stateChanged;

xmlHttp.open("POST",url,true);

xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      xmlHttp.setRequestHeader("Content-length", params.length);
      xmlHttp.setRequestHeader("Connection", "close");
      xmlHttp.send(params);

function stateChanged() 
{ 
if (xmlHttp.readyState==1)
{
document.getElementById("divBody").innerHTML = "Please wait, Loading....";
}

if (xmlHttp.readyState==4)
{ 
var headID = document.getElementsByTagName("head")[0];         
var newScript = document.createElement('script');
newScript.type = 'text/javascript';
newScript.src = './clientscript/mainScreen.js';
headID.appendChild(newScript);
mainScreen();
}
}
}


 

It works fine with the readystate==4, but when I add the readystate==1, the readystate==4 doesn't follow through, what do I have to do?

 

Link to comment
https://forums.phpfreaks.com/topic/140624-solved-multiple-readystate/
Share on other sites

That should work fine....  What do you mean it doesn't follow through?

 

 

Although, I must say I have an issue with your script.  To be specific, it relies on global variables.  Perhaps use this instead of xmlHttp inside of the callback function?  If you ever decide to change the variable name or something later, you would have to go through and replace them all.  (Ok find/replace would do that, but there could be more complex situations ;p.)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.