Skip to content
Snippets Groups Projects
Commit 2228bd10 authored by Alexander Plavin's avatar Alexander Plavin
Browse files

hgweb: add makeRequest javascript function

This function performs an asynchronous HTTP request and calls provided
callbacks:
- onstart: request is sent
- onsuccess: response is received
- onerror: some error occured
- oncomplete: response is fully processed and all other callbacks finished
parent 5bdc179e
No related branches found
No related tags found
No related merge requests found
......@@ -304,3 +304,27 @@
return String(replacements[p1]);
});
}
function makeRequest(url, method, onstart, onsuccess, onerror, oncomplete) {
xfr = new XMLHttpRequest();
xfr.onreadystatechange = function() {
if (xfr.readyState === 4) {
try {
if (xfr.status === 200) {
onsuccess(xfr.responseText);
} else {
throw 'server error';
}
} catch (e) {
onerror(e);
} finally {
oncomplete();
}
}
};
xfr.open(method, url);
xfr.send();
onstart();
return xfr;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment