summaryrefslogtreecommitdiff
path: root/common/ajax.js
blob: 8082bbedcadc7b7b3fa25a36cbb33bacd6053a74 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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
 */
18-07-27 18:52:58 +0200'>2018-07-27gnu: gcc@8: Update to 8.2.0....Ludovic Courtès 2018-07-24Merge branch 'master' into core-updatesMarius Bakke 2018-07-02Merge branch 'master' into stagingMarius Bakke 2018-06-29Merge branch 'master' into core-updatesRicardo Wurmus 2018-06-26gnu: Add gcc@8....Marius Bakke 2018-06-14gnu: custom-gcc: Fix regex used for matching executables....Alex Vong 2018-06-12gnu: isl: Update to 0.19....Tobias Geerinckx-Rice 2018-05-08Merge branch 'master' into core-updatesMark H Weaver 2018-05-07gnu: gcc > 5: Use 'CPATH' instead of 'C_INCLUDE_PATH' & co....Ludovic Courtès 2018-04-21gnu: gcc@4.7: Combine duplicate 'patches' fields into one....Mark H Weaver 2018-04-12gnu: gnu-c-manual: Use invoke....Mark H Weaver 2018-04-12gnu: libstdc++-doc: Use invoke....Mark H Weaver