XpertWorlock Posted January 13, 2009 Share Posted January 13, 2009 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? Quote Link to comment Share on other sites More sharing options...
corbin Posted January 13, 2009 Share Posted January 13, 2009 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.) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.