diff options
Diffstat (limited to 'lib/js')
-rw-r--r-- | lib/js/urweb.js | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/lib/js/urweb.js b/lib/js/urweb.js index d5147369..18842188 100644 --- a/lib/js/urweb.js +++ b/lib/js/urweb.js @@ -115,9 +115,13 @@ function pfl(s) { throw "Can't parse float: " + s; } +function whine(msg) { + alert(msg); + throw msg; +} + function pf() { - alert("Pattern match failure"); - throw "Pattern match failure"; + whine("Pattern match failure"); } var closures = []; @@ -180,8 +184,7 @@ function rc(uri, parse, k) { if (isok) k(parse(xhr.responseText)); else { - alert("Error querying remote server!"); - throw "Error querying remote server!"; + whine("Error querying remote server!"); } } }; @@ -200,8 +203,7 @@ function path_join(s1, s2) { function listener() { var uri = path_join(url_prefix, ".msgs"); var xhr = getXHR(); - - xhr.onreadystatechange = function() { + var orsc = function() { if (xhr.readyState == 4) { var isok = false; @@ -211,15 +213,23 @@ function listener() { } catch (e) { } if (isok) { - alert("Messages: " + xhr.responseText); + var lines = xhr.responseText.split("\n"); + if (lines.length < 2) + whine("Empty message from remote server"); + + for (var i = 0; i+1 < lines.length; i += 2) { + alert("Message(" + lines[i] + "): " + lines[i+1]); + } + + xhr.onreadystatechange = orsc; requestUri(xhr, uri); } else { - alert("Error querying remote server for messages!"); - throw "Error querying remote server for messages!"; + whine("Error querying remote server for messages!"); } } }; + xhr.onreadystatechange = orsc; requestUri(xhr, uri); } |