Accessing Intranet Applications
We have an intranet application and users are supposed to get this intranet application launched first thing when they login (using login scripts). In order to accomplish this, we have created a HTML page which checks if the webserver is up and running by looking up a static page on the web server and if the HTTP request is OK, redirect to the intranet homepage, if not, deliver a friendly message providing links to various other services.
Problem:
For some reasons, the HTML page (on the local machine), just remains blank (there is no network down message, no Page Cannot be Displayed) etc., even when the intranet application is working fine.
Also, if the service is down (for some reason, the network goes down, the AppServer goes down, etc.,), this local page takes ages to load and never times out, often forcing users to "End Task" internet explorer.
Is there an efficient way of achieving the same?
Now, truth be told, I quite do not understand XMLHttp on how it works in detail, but the below code makes sense to me (although there are too many functions - for example, they call networkAvailable and then call redirectBrowser etc., when they can just call redirectBrowser - but that is just my opinion)
Can someone please help me in understanding why the local HTML page just remains blank
The following is the relevant code -
var iTimeOut = 60;
var iTimerID, iSendTime;
var iTimerStop = false;
var oXMLHTTP = new ActiveXObject("Microsoft.XMLHTTP");
oXMLHTTP.onreadystatechange = requestStateChanged;
sendRequestToNetwork();
function sendRequestToNetwork(){
var dSend = new Date();
iSendTime = dSend.getMilliseconds;
iTimerID = window.setTimeout("requestTimedOut()",iTimeOut)
try{
oXMLHTTP.open("GET",sTestURL,false);
oXMLHTTP.onreadystatechange = requestStateChanged;
oXMLHTTP.send();}
catch(er)
{} // I guess we're not on any network.
}
function requestStateChanged(){
if (oXMLHTTP.readyState==4){
var sc = getStatusText(oXMLHTTP.status);
if (sc=='')
{} // The request is going to time out.
else{
iTimerStop = true;
responseReceived(sc)}
}
}
function responseReceived(sMsg){
if ((oXMLHTTP.status >= 200) && (oXMLHTTP.status < 300))
{networkAvailable();}
else {networkDown(sMsg);}
}
function networkAvailable(){
redirectBrowser(sLaunchURL)}
function networkDown(sMsg){
html=html+'<p><br><br><br>The technical reason was : '+sMsg+'</p></body></HTML>';
document.body.innerHTML=html;
}
function redirectBrowser(sNewURL)
{window.location.replace(sNewURL)}
function requestTimedOut(){
if (iTimerStop == false){
var sMsg = 'Request timed out after '+(iTimeOut/1000)+' second/s.' + getStatusText(oXMLHTTP.status);
if (oXMLHTTP.readystate == 4){
responseReceived(sMsg)}
else {networkDown(sMsg)}
}
}
function getStatusText(statuscode){
if (statuscode < 500){
if ((statuscode >= 200) && (statuscode < 300))
{return 'Successful Connection.'}
else if (statuscode==403)
{return "FORBIDDEN - access not required even with authorization."}
else if (statuscode==404)
{return "NOT FOUND - server could not find the given resource."}
else
{return 'Status Code: ' + statuscode}
}
else {return '';}
}