Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/MHSanaei/3x-ui.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'web/assets/js/util/utils.js')
-rw-r--r--web/assets/js/util/utils.js35
1 files changed, 35 insertions, 0 deletions
diff --git a/web/assets/js/util/utils.js b/web/assets/js/util/utils.js
index 30f1f6a2..28ec95c7 100644
--- a/web/assets/js/util/utils.js
+++ b/web/assets/js/util/utils.js
@@ -70,6 +70,41 @@ class HttpUtil {
}
return msg;
}
+
+ static async jsonPost(url, data) {
+ let msg;
+ try {
+ const requestOptions = {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ },
+ body: JSON.stringify(data),
+ };
+ const resp = await fetch(url, requestOptions);
+ const response = await resp.json();
+
+ msg = this._respToMsg({data : response});
+ } catch (e) {
+ msg = new Msg(false, e.toString());
+ }
+ this._handleMsg(msg);
+ return msg;
+ }
+
+ static async postWithModalJson(url, data, modal) {
+ if (modal) {
+ modal.loading(true);
+ }
+ const msg = await this.jsonPost(url, data);
+ if (modal) {
+ modal.loading(false);
+ if (msg instanceof Msg && msg.success) {
+ modal.close();
+ }
+ }
+ return msg;
+ }
}
class PromiseUtil {