mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-01-29 09:01:54 +08:00
refactoring
This commit is contained in:
@@ -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);
|
||||
};
|
||||
|
||||
/************************************************************************/
|
||||
|
||||
Reference in New Issue
Block a user