summaryrefslogtreecommitdiff
path: root/web/share/js/tools.js
diff options
context:
space:
mode:
Diffstat (limited to 'web/share/js/tools.js')
-rw-r--r--web/share/js/tools.js17
1 files changed, 14 insertions, 3 deletions
diff --git a/web/share/js/tools.js b/web/share/js/tools.js
index 3aa66532..fbf712de 100644
--- a/web/share/js/tools.js
+++ b/web/share/js/tools.js
@@ -39,16 +39,27 @@ export var tools = new function() {
/************************************************************************/
- self.makeRequest = function(method, url, callback, body=null, content_type=null, timeout=15000) {
+ self.httpRequest = function(method, url, callback, body=null, content_type=null, timeout=15000) {
let http = new XMLHttpRequest();
http.open(method, url, true);
if (content_type) {
http.setRequestHeader("Content-Type", content_type);
}
- http.onreadystatechange = callback;
+ http.onreadystatechange = function() {
+ if (http.readyState === 4) {
+ callback(http);
+ }
+ };
http.timeout = timeout;
http.send(body);
- return http;
+ };
+
+ self.httpGet = function(url, callback, body=null, content_type=null, timeout=15000) {
+ self.httpRequest("GET", url, callback, body, content_type, timeout);
+ };
+
+ self.httpPost = function(url, callback, body=null, content_type=null, timeout=15000) {
+ self.httpRequest("POST", url, callback, body, content_type, timeout);
};
/************************************************************************/