comparison lib/js/urweb.js @ 669:f68eee90dbcf

Press a button to send a message
author Adam Chlipala <adamc@hcoop.net>
date Sun, 22 Mar 2009 15:16:34 -0400
parents b0c1a46b1f15
children f73913d97a40
comparison
equal deleted inserted replaced
668:b0c1a46b1f15 669:f68eee90dbcf
113 return r; 113 return r;
114 else 114 else
115 throw "Can't parse float: " + s; 115 throw "Can't parse float: " + s;
116 } 116 }
117 117
118 function whine(msg) {
119 alert(msg);
120 throw msg;
121 }
122
118 function pf() { 123 function pf() {
119 alert("Pattern match failure"); 124 whine("Pattern match failure");
120 throw "Pattern match failure";
121 } 125 }
122 126
123 var closures = []; 127 var closures = [];
124 128
125 function ca(f) { 129 function ca(f) {
178 } catch (e) { } 182 } catch (e) { }
179 183
180 if (isok) 184 if (isok)
181 k(parse(xhr.responseText)); 185 k(parse(xhr.responseText));
182 else { 186 else {
183 alert("Error querying remote server!"); 187 whine("Error querying remote server!");
184 throw "Error querying remote server!";
185 } 188 }
186 } 189 }
187 }; 190 };
188 191
189 requestUri(xhr, uri); 192 requestUri(xhr, uri);
198 } 201 }
199 202
200 function listener() { 203 function listener() {
201 var uri = path_join(url_prefix, ".msgs"); 204 var uri = path_join(url_prefix, ".msgs");
202 var xhr = getXHR(); 205 var xhr = getXHR();
203 206 var orsc = function() {
204 xhr.onreadystatechange = function() {
205 if (xhr.readyState == 4) { 207 if (xhr.readyState == 4) {
206 var isok = false; 208 var isok = false;
207 209
208 try { 210 try {
209 if (xhr.status == 200) 211 if (xhr.status == 200)
210 isok = true; 212 isok = true;
211 } catch (e) { } 213 } catch (e) { }
212 214
213 if (isok) { 215 if (isok) {
214 alert("Messages: " + xhr.responseText); 216 var lines = xhr.responseText.split("\n");
217 if (lines.length < 2)
218 whine("Empty message from remote server");
219
220 for (var i = 0; i+1 < lines.length; i += 2) {
221 alert("Message(" + lines[i] + "): " + lines[i+1]);
222 }
223
224 xhr.onreadystatechange = orsc;
215 requestUri(xhr, uri); 225 requestUri(xhr, uri);
216 } 226 }
217 else { 227 else {
218 alert("Error querying remote server for messages!"); 228 whine("Error querying remote server for messages!");
219 throw "Error querying remote server for messages!";
220 } 229 }
221 } 230 }
222 }; 231 };
223 232
233 xhr.onreadystatechange = orsc;
224 requestUri(xhr, uri); 234 requestUri(xhr, uri);
225 } 235 }