Added Scholar.HTTP.browserIsOffline() and changed doGet() and doPost() to return false if so
This commit is contained in:
parent
11a056ecd4
commit
2d20fe717d
1 changed files with 29 additions and 0 deletions
|
@ -327,8 +327,18 @@ Scholar.HTTP = new function(){
|
||||||
|
|
||||||
this.doGet = doGet;
|
this.doGet = doGet;
|
||||||
this.doPost = doPost;
|
this.doPost = doPost;
|
||||||
|
this.browserIsOffline = browserIsOffline;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send an HTTP GET request via XMLHTTPRequest
|
||||||
|
*
|
||||||
|
* Returns false if browser is offline
|
||||||
|
**/
|
||||||
function doGet(url, onStatus, onDone){
|
function doGet(url, onStatus, onDone){
|
||||||
|
if (this.browserIsOffline()){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
var xmlhttp = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"]
|
var xmlhttp = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"]
|
||||||
.createInstance();
|
.createInstance();
|
||||||
|
|
||||||
|
@ -338,10 +348,21 @@ Scholar.HTTP = new function(){
|
||||||
_stateChange(xmlhttp, onStatus, onDone);
|
_stateChange(xmlhttp, onStatus, onDone);
|
||||||
};
|
};
|
||||||
xmlhttp.send(null);
|
xmlhttp.send(null);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send an HTTP POST request via XMLHTTPRequest
|
||||||
|
*
|
||||||
|
* Returns false if browser is offline
|
||||||
|
**/
|
||||||
function doPost(url, body, onStatus, onDone){
|
function doPost(url, body, onStatus, onDone){
|
||||||
|
if (this.browserIsOffline()){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
var xmlhttp = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"]
|
var xmlhttp = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"]
|
||||||
.createInstance();
|
.createInstance();
|
||||||
|
|
||||||
|
@ -351,6 +372,14 @@ Scholar.HTTP = new function(){
|
||||||
_stateChange(xmlhttp, onStatus, onDone);
|
_stateChange(xmlhttp, onStatus, onDone);
|
||||||
};
|
};
|
||||||
xmlhttp.send(body);
|
xmlhttp.send(body);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function browserIsOffline(){
|
||||||
|
return Components.classes["@mozilla.org/network/io-service;1"]
|
||||||
|
.getService(Components.interfaces.nsIIOService).offline;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue