diff lib/js/urweb.js @ 668:b0c1a46b1f15

First message send delivered, but not interpreted
author Adam Chlipala <adamc@hcoop.net>
date Sun, 22 Mar 2009 15:05:07 -0400
parents a93d5324f400
children f68eee90dbcf
line wrap: on
line diff
--- a/lib/js/urweb.js	Thu Mar 19 16:34:13 2009 -0400
+++ b/lib/js/urweb.js	Sun Mar 22 15:05:07 2009 -0400
@@ -133,7 +133,11 @@
 }
 
 
-function getXHR()
+var client_id = 0;
+var client_pass = 0;
+var url_prefix = "/";
+
+function getXHR(uri)
 {
   try {
     return new XMLHttpRequest();
@@ -150,6 +154,17 @@
   }
 }
 
+function requestUri(xhr, uri) {
+  xhr.open("GET", uri, true);
+
+  if (client_id != 0) {
+    xhr.setRequestHeader("UrWeb-Client", client_id.toString());
+    xhr.setRequestHeader("UrWeb-Pass", client_pass.toString());
+  }
+
+  xhr.send(null);
+}
+
 function rc(uri, parse, k) {
   var xhr = getXHR();
 
@@ -171,15 +186,10 @@
     }
   };
 
-  xhr.open("GET", uri, true);
-  xhr.send(null);
+  requestUri(xhr, uri);
 }
 
 
-var client_id = 0;
-var client_pass = 0;
-var url_prefix = "/";
-
 function path_join(s1, s2) {
   if (s1.length > 0 && s1[s1.length-1] == '/')
     return s1 + s2;
@@ -188,6 +198,7 @@
 }
 
 function listener() {
+  var uri = path_join(url_prefix, ".msgs");
   var xhr = getXHR();
 
   xhr.onreadystatechange = function() {
@@ -199,8 +210,10 @@
           isok = true;
       } catch (e) { }
 
-      if (isok)
+      if (isok) {
         alert("Messages: " + xhr.responseText);
+        requestUri(xhr, uri);
+      }
       else {
         alert("Error querying remote server for messages!");
         throw "Error querying remote server for messages!";
@@ -208,6 +221,5 @@
     }
   };
 
-  xhr.open("GET", path_join(url_prefix, ".msgs/" + client_id + "/" + client_pass), true);
-  xhr.send(null);
+  requestUri(xhr, uri);
 }