diff options
author | Wojtek Kosior <koszko@koszko.org> | 2021-08-14 10:07:28 +0200 |
---|---|---|
committer | Wojtek Kosior <koszko@koszko.org> | 2021-08-14 10:07:28 +0200 |
commit | 443bc095a72949adb4a007c9a19a43da7dd8843d (patch) | |
tree | 4b3e392057d8939961a3e707ae596cd85e6fa623 /common/ajax.js | |
parent | ae1844f9ac935eb3c89314cd402b4ec2c3d0f537 (diff) | |
parent | 2fbab2f07d3cebde1fba0e801df4f3e9129e463b (diff) | |
download | browser-extension-443bc095a72949adb4a007c9a19a43da7dd8843d.tar.gz browser-extension-443bc095a72949adb4a007c9a19a43da7dd8843d.zip |
merge facility to install from Hydrilla
Diffstat (limited to 'common/ajax.js')
-rw-r--r-- | common/ajax.js | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/common/ajax.js b/common/ajax.js new file mode 100644 index 0000000..8082bbe --- /dev/null +++ b/common/ajax.js @@ -0,0 +1,39 @@ +/** + * part of Hachette + * Wrapping XMLHttpRequest into a Promise. + * + * Copyright (C) 2021 Wojtek Kosior + * Redistribution terms are gathered in the `copyright' file. + */ + +function ajax_callback() +{ + if (this.readyState == 4) + this.resolve_callback(this); +} + +function initiate_ajax_request(resolve, reject, method, url) +{ + const xhttp = new XMLHttpRequest(); + xhttp.resolve_callback = resolve; + xhttp.onreadystatechange = ajax_callback; + xhttp.open(method, url, true); + try { + xhttp.send(); + } catch(e) { + console.log(e); + setTimeout(reject, 0); + } +} + +function make_ajax_request(method, url) +{ + return new Promise((resolve, reject) => + initiate_ajax_request(resolve, reject, method, url)); +} + +/* + * EXPORTS_START + * EXPORT make_ajax_request + * EXPORTS_END + */ |