I personally finished testing for the answer == "" and status == 0.
var req = new XMLHttpRequest(); req.open("post", VALIDATE_URL, true); req.onreadystatechange = function receiveResponse() { if (this.readyState == 4) { if (this.status == 200) { console.log("We go a response : " + this.response); } else if (!isValid(this.response) && this.status == 0) { console.log("The computer appears to be offline."); } } }; req.send(payload); req = null;
source share