You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@roller.apache.org by sn...@apache.org on 2006/03/17 21:46:51 UTC

svn commit: r386709 - /incubator/roller/trunk/web/theme/scripts/clientSideInclude.js

Author: snoopdave
Date: Fri Mar 17 12:46:49 2006
New Revision: 386709

URL: http://svn.apache.org/viewcvs?rev=386709&view=rev
Log:
Switched to async XMLHttpRequest call to resolve ROL-1082, code from Oscar del Rio

Modified:
    incubator/roller/trunk/web/theme/scripts/clientSideInclude.js

Modified: incubator/roller/trunk/web/theme/scripts/clientSideInclude.js
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/web/theme/scripts/clientSideInclude.js?rev=386709&r1=386708&r2=386709&view=diff
==============================================================================
--- incubator/roller/trunk/web/theme/scripts/clientSideInclude.js (original)
+++ incubator/roller/trunk/web/theme/scripts/clientSideInclude.js Fri Mar 17 12:46:49 2006
@@ -1,5 +1,8 @@
+// global vars for access from callback function
+var req = false;
+var element;
+
 function clientSideInclude(id, url) {
-  var req = false;
   // For Safari, Firefox, and other non-MS browsers
   if (window.XMLHttpRequest) {
     try {
@@ -19,7 +22,8 @@
       }
     }
   }
- var element = document.getElementById(id);
+ // var element = document.getElementById(id);
+ element = document.getElementById(id);
  if (!element) {
   alert("Bad id " + id +
    "passed to clientSideInclude." +
@@ -28,16 +32,23 @@
   return;
  }
   if (req) {
-    // Synchronous request, wait till we have it all
-    req.open('GET', url, false);
+    // Asynchronous request using processReqChange callback
+    req.onreadystatechange = processReqChange;
+    req.open('GET', url, true);
     req.send(null);
-    element.innerHTML = req.responseText;
-  } else {
-    element.innerHTML =
-   "Sorry, your browser does not support " +
-      "XMLHTTPRequest objects. This page requires " +
-      "Internet Explorer 5 or better for Windows, " +
-      "or Firefox for any system, or Safari. Other " +
-      "compatible browsers may also exist.";
   }
-}
\ No newline at end of file
+}
+
+// handle onreadystatechange event of req object
+function processReqChange() {
+    // only if req shows "loaded"
+    if (req.readyState == 4) {
+        // only if "OK"
+        if (req.status == 200) {
+            element.innerHTML = req.responseText;
+         } else {
+            alert("There was a problem retrieving the XML data:\n" +
+                req.statusText);
+         }
+    }
+} 
\ No newline at end of file