blob: befcc442aa8670b27490e219562aebd2f6e7b438 (
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
|
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 ) {
if( xhr.status === 200 ) {
callback(xhr.responseText);
} else if ( xhr.status === 400 ) {
console.log(xhr.responseText);
}
}
};
xhr.send();
}
|