aboutsummaryrefslogtreecommitdiffstats
path: root/python/risk_insight/static/utils.js
blob: a4ab6dd5d432d1a1e3f7fe6c8ef7ecd6ae4f7caf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
function $(s) {
    return( document.getElementById(s) );
}

function encode_dict(d){
    var r = [];
    for(var k in d){
        r.push(encodeURIComponent(k) + '=' + encodeURIComponent(d[k]));
    }
    return r.join('&');
}

function query(url, params, callback){
    var xhr = new XMLHttpRequest();
    xhr.open('GET', url + '?' + encode_dict(params));
    xhr.onreadystatechange = function() {
        if( xhr.readyState === 4){
            callback(xhr.responseText);
        }
    };
    xhr.send();
}