1,105,578 Community Members

XMLHttpRequest set timeout

Member Avatar
eburlea
Junior Poster
112 posts since Apr 2012
Reputation Points: 23 [?]
Q&As Helped to Solve: 4 [?]
Skill Endorsements: 0 [?]
 
0
 

Hello. I have a function that checks the internet connection. I need to set a timeout to it. I have tried without success to do that. Please help. Here is the function:

function isOnline() {
    if(navigator.onLine){
        var uri = baseUrl+'ping';
        var xhr = new XMLHttpRequest();
        xhr.open('GET',uri,false);
        try{
            xhr.send();
            return true;
        }catch(err){
            return false;
        }
    }else{
        return false;
    }


}
Member Avatar
stbuchok
Posting Shark
957 posts since May 2011
Reputation Points: 123 [?]
Q&As Helped to Solve: 142 [?]
Skill Endorsements: 2 [?]
 
0
 
You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: