[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Cluster-devel] conga/luci/plone-custom conga_ajax.js



CVSROOT:	/cvs/cluster
Module name:	conga
Changes by:	rmccabe sourceware org	2007-11-12 17:10:43

Modified files:
	luci/plone-custom: conga_ajax.js 

Log message:
	support async POST requests

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/plone-custom/conga_ajax.js.diff?cvsroot=cluster&r1=1.3&r2=1.4

--- conga/luci/plone-custom/conga_ajax.js	2007/08/08 21:26:37	1.3
+++ conga/luci/plone-custom/conga_ajax.js	2007/11/12 17:10:43	1.4
@@ -9,7 +9,7 @@
 
 var xmlHttp_object = false;
 
-function initiate_async_get(url, callback_function) {
+function get_xmlhttp_obj() {
 	xmlHttp_object = false;
 
 	if (!xmlHttp_object && typeof XMLHttpRequest != 'undefined') {
@@ -27,14 +27,48 @@
 			}
 		}
 	}
+	return (xmlHttp_object);
+}
 
-	if (xmlHttp_object) {
-		xmlHttp_object.open("GET", url, true);
-		xmlHttp_object.onreadystatechange = callback_function;
-		xmlHttp_object.send(null);
-	} else {
+function initiate_async_get(url, callback_function) {
+	xmlHttp_object = get_xmlhttp_obj();
+
+	if (!xmlHttp_object) {
+		alert("Unable to communicate with the luci server.");
+		return (-1);
+	}
+
+	xmlHttp_object.open("GET", url, true);
+	xmlHttp_object.onreadystatechange = callback_function;
+	xmlHttp_object.send(null);
+}
+
+function initiate_async_post(form, url, callback) {
+	xmlHttp_object = get_xmlhttp_obj();
+	if (!xmlHttp_object) {
 		alert("Unable to communicate with the luci server.");
+		return (-1);
 	}
+
+	var form_data_str = '';
+	for (var i = 0 ; i < form.elements.length ; i++) {
+		switch (form.elements[i].type) {
+			case 'hidden':
+			case 'password':
+			case 'select-one':
+			case 'text':
+			case 'textarea':
+				form_data_str += form.elements[i].name + '=' +
+					escape(form.elements[i].value) + '&';
+		}
+	}
+
+	xmlHttp_object.onreadystatechange = callback;
+	xmlHttp_object.open('POST', url, true);
+	xmlHttp_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
+	xmlHttp_object.setRequestHeader("Content-length", form_data_str.length);
+	xmlHttp_object.setRequestHeader("Connection", "close");
+	xmlHttp_object.send(form_data_str);
 }
 
 function get_ajax_msgs(obj, tag_name) {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]