Mercurial > hg
changeset 19740:2228bd109706
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
author | Alexander Plavin <alexander@plav.in> |
---|---|
date | Fri, 06 Sep 2013 13:30:57 +0400 |
parents | 5bdc179e58c1 |
children | 2a9a21e1e1db |
files | mercurial/templates/static/mercurial.js |
diffstat | 1 files changed, 24 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/templates/static/mercurial.js Fri Sep 06 13:30:57 2013 +0400 +++ b/mercurial/templates/static/mercurial.js Fri Sep 06 13:30:57 2013 +0400 @@ -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; +}