summaryrefslogtreecommitdiff
path: root/httemplate/elements/xmlhttp.html
diff options
context:
space:
mode:
authorivan <ivan>2005-09-10 14:50:57 +0000
committerivan <ivan>2005-09-10 14:50:57 +0000
commit9e342300c380e29af1b9678f1a9604609e0061b6 (patch)
tree72d0edb8de70b19465264c76669045b0ba202e6e /httemplate/elements/xmlhttp.html
parent3502e0627909ea99683d1724adb0d4a3fee578b2 (diff)
ajax-style xmlhttprequest state/county/country selector!
Diffstat (limited to 'httemplate/elements/xmlhttp.html')
-rw-r--r--httemplate/elements/xmlhttp.html65
1 files changed, 65 insertions, 0 deletions
diff --git a/httemplate/elements/xmlhttp.html b/httemplate/elements/xmlhttp.html
new file mode 100644
index 000000000..425e28e3d
--- /dev/null
+++ b/httemplate/elements/xmlhttp.html
@@ -0,0 +1,65 @@
+<%
+ my ( $url, @subs ) = @_;
+
+ $url .= ( ($url =~ /\?/) ? '&' : '?' ).
+ 'sub=';
+
+%>
+
+<SCRIPT TYPE="text/javascript">
+
+ function rs_init_object() {
+ var A;
+ try {
+ A=new ActiveXObject("Msxml2.XMLHTTP");
+ } catch (e) {
+ try {
+ A=new ActiveXObject("Microsoft.XMLHTTP");
+ } catch (oc) {
+ A=null;
+ }
+ }
+ if(!A && typeof XMLHttpRequest != "undefined")
+ A = new XMLHttpRequest();
+ if (!A)
+ alert("Can't create XMLHttpRequest object");
+ return A;
+
+ }
+
+ <% foreach my $func (@subs) {
+
+ my $furl = $url . uri_escape($func);
+ $furl =~ s/\"/\\\\\"/; #javascript escape
+
+ %>
+
+ function <%=$func%>() {
+ // count args; build URL
+ var url = "<%=$furl%>";
+ var a = <%=$func%>.arguments;
+ for (var i = 0; i < a.length-1; i++)
+ url = url + "&arg=" + escape(a[i]);
+ url = url.replace( /[+]/g, '%2B'); // fix the unescaped plus signs
+ var xmlhttp = rs_init_object();
+ xmlhttp.open("GET", url, true);
+ xmlhttp.onreadystatechange = function() {
+ if (xmlhttp.readyState != 4)
+ return;
+ //rs_debug("received " + x.responseText);
+
+ if (xmlhttp.status != 200) {
+ alert(xmlhttp.status + " status connecting to " + url);
+ } else {
+ var data = xmlhttp.responseText;
+ a[a.length-1](data);
+ }
+ }
+ xmlhttp.send(null);
+ //rs_debug("x_$func_name url = " + url);
+ //rs_debug("x_$func_name waiting..");
+ }
+
+ <% } %>
+
+</SCRIPT>