You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by lg...@apache.org on 2005/05/14 17:42:24 UTC

svn commit: r170143 - /cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/resources/js/cforms.js

Author: lgawron
Date: Sat May 14 08:42:22 2005
New Revision: 170143

URL: http://svn.apache.org/viewcvs?rev=170143&view=rev
Log:
XMLHttpRequest.send seems to choke if request uri is empty. 
Lots of users use <ft:form action=""/> and pass continuation id in a hidden field. 
This fix uses document.location if specified form.action is empty.

Modified:
    cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/resources/js/cforms.js

Modified: cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/resources/js/cforms.js
URL: http://svn.apache.org/viewcvs/cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/resources/js/cforms.js?rev=170143&r1=170142&r2=170143&view=diff
==============================================================================
--- cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/resources/js/cforms.js (original)
+++ cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/resources/js/cforms.js Sat May 14 08:42:22 2005
@@ -50,7 +50,11 @@
         
         var req = CForms.newXMLHttpRequest();
         if (req) {
-            req.open("POST", form.action, true);
+            var uri = form.action;
+            if ( uri == "" )
+                uri = document.location;
+                
+            req.open("POST", uri, true);
             req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
             // onreadystatechange must be all lower case (?)
             req.onreadystatechange = function() {
@@ -78,11 +82,11 @@
  */
 CForms.newXMLHttpRequest = function () {
     if (this.ajax) {
-	    if (window.XMLHttpRequest)
-	        return new XMLHttpRequest;
-	    else if (window.ActiveXObject)
-	        return new ActiveXObject("Microsoft.XMLHTTP");
-	}
+        if (window.XMLHttpRequest)
+            return new XMLHttpRequest;
+        else if (window.ActiveXObject)
+            return new ActiveXObject("Microsoft.XMLHTTP");
+    }
 }
 
 /**
@@ -120,21 +124,21 @@
         } catch (e) {
             // header doesn't exist
         }
-	    if (xca == "continue") {
-	        // Interaction with this page is finished: redirect the browser to the form's action URL
-	        // Get the continuation-id, if any.
-	        var contParam = '?cocoon-ajax-continue=true';
-	        if (form.elements["continuation-id"]) {
-	            contParam = "&continuation-id=" + form.elements["continuation-id"].value;
-	        }
-	        window.location.href = form.action + contParam;
-	    } else {
-	        // Handle browser update directives
-	        var doc = request.responseXML;
-	        if (!doc) {
-	            alert("no xml answer");
-	            return;
-	        }
+        if (xca == "continue") {
+            // Interaction with this page is finished: redirect the browser to the form's action URL
+            // Get the continuation-id, if any.
+            var contParam = '?cocoon-ajax-continue=true';
+            if (form.elements["continuation-id"]) {
+                contParam = "&continuation-id=" + form.elements["continuation-id"].value;
+            }
+            window.location.href = form.action + contParam;
+        } else {
+            // Handle browser update directives
+            var doc = request.responseXML;
+            if (!doc) {
+                alert("no xml answer");
+                return;
+            }
         
            BrowserUpdate.processResponse(doc);
        }
@@ -262,33 +266,33 @@
     }
 }
 BrowserUpdate.handlers = {
-	replace :  function(element) {
-	    var id = element.getAttribute("id");
-	    if (!id) {
-	       alert("no id found on update element");
-	       return;
-	    }    
-	    // Get the first child element (the first child not may be some text!)
-	    var firstChild = DOMUtils.firstChildElement(element);
-	
-	    var oldElement = document.getElementById(id);
-	    
-	    if (!oldElement) {
-	        alert("no element '" + id + "' in source document");
-	        return;
-	    }
-	
-	    var newElement = DOMUtils.importNode(firstChild, document);
-	    
-	    // Warn: it's replace(new, old)!!
-	    oldElement.parentNode.replaceChild(newElement, oldElement);
-	    // Ensure the new node has the correct id
-	    newElement.setAttribute("id", id);
-	    
-	    if (BrowserUpdate.highlight) {
-	       BrowserUpdate.highlight(newElement);
-	    }
-	}
+    replace :  function(element) {
+        var id = element.getAttribute("id");
+        if (!id) {
+           alert("no id found on update element");
+           return;
+        }    
+        // Get the first child element (the first child not may be some text!)
+        var firstChild = DOMUtils.firstChildElement(element);
+    
+        var oldElement = document.getElementById(id);
+        
+        if (!oldElement) {
+            alert("no element '" + id + "' in source document");
+            return;
+        }
+    
+        var newElement = DOMUtils.importNode(firstChild, document);
+        
+        // Warn: it's replace(new, old)!!
+        oldElement.parentNode.replaceChild(newElement, oldElement);
+        // Ensure the new node has the correct id
+        newElement.setAttribute("id", id);
+        
+        if (BrowserUpdate.highlight) {
+           BrowserUpdate.highlight(newElement);
+        }
+    }
 }
 
 //-------------------------------------------------------------------------------------------------