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
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.)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.