kyle83
IS-IT--Management
- Aug 4, 2006
- 8
Hi everyone,
I'm having some trouble writing a function that periodically checks the user's connection. Basically I want to use setInterval to call the follownig function every 15 seconds or so.. The function will try and load a blank page (null.php). If it gets no response (readstate doesn't reach 4), then i need it to pop up a notification layer to alert the user that the connection has failed. I thought of implemeting a timer somewhere inside the function (if it doesn't receive a response for so many seconds then show the alert). But, I'm not quite sure how to do this because I'm thinking the setInterval would need to be extended to wait for the function (if its taking a bit long to receive a response).
Can anyone give me a tip on how to beef up this script to pull this off? Or If anyone has a completely better way of doing this, that would be appreciated too.. Thanks in advance everyone..
function isConnected(){
var thepage = 'null.php';
var xhReq = createXMLHttpRequest();
xhReq.open("GET",'pages/' + thepage,true);
xhReq.onreadystatechange = onSumResponse;
xhReq.send(null);
function onSumResponse(){
if (xhReq.readyState != 4){
return;
}
else{
// Is Connected, No Alert
}
}
}
I'm having some trouble writing a function that periodically checks the user's connection. Basically I want to use setInterval to call the follownig function every 15 seconds or so.. The function will try and load a blank page (null.php). If it gets no response (readstate doesn't reach 4), then i need it to pop up a notification layer to alert the user that the connection has failed. I thought of implemeting a timer somewhere inside the function (if it doesn't receive a response for so many seconds then show the alert). But, I'm not quite sure how to do this because I'm thinking the setInterval would need to be extended to wait for the function (if its taking a bit long to receive a response).
Can anyone give me a tip on how to beef up this script to pull this off? Or If anyone has a completely better way of doing this, that would be appreciated too.. Thanks in advance everyone..
function isConnected(){
var thepage = 'null.php';
var xhReq = createXMLHttpRequest();
xhReq.open("GET",'pages/' + thepage,true);
xhReq.onreadystatechange = onSumResponse;
xhReq.send(null);
function onSumResponse(){
if (xhReq.readyState != 4){
return;
}
else{
// Is Connected, No Alert
}
}
}