summaryrefslogtreecommitdiff
path: root/httemplate/elements/xmlhttp.html
diff options
context:
space:
mode:
Diffstat (limited to 'httemplate/elements/xmlhttp.html')
-rw-r--r--httemplate/elements/xmlhttp.html79
1 files changed, 79 insertions, 0 deletions
diff --git a/httemplate/elements/xmlhttp.html b/httemplate/elements/xmlhttp.html
new file mode 100644
index 000000000..41965ace2
--- /dev/null
+++ b/httemplate/elements/xmlhttp.html
@@ -0,0 +1,79 @@
+<%
+ my ( %opt ) = @_;
+
+ my $url = $opt{'url'};
+ #my $action = exists $opt{'action'} ? $opt{'action'} : 'GET';
+ #my @subs = @{ $opt{'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 ( @{$opt{'subs'}} ) {
+
+ my $furl = $url . uri_escape($func);
+ $furl =~ s/\"/\\\\\"/; #javascript escape
+
+ %>
+
+ function <%=$func%>() {
+ // count args; build URL
+ var url = "<%=$furl%>";
+ var a = <%=$func%>.arguments;
+ var args;
+ var len;
+ if ( a && typeof a == 'object' && a[0].constructor == Array ) {
+ args = a[0];
+ len = args.length
+ } else {
+ args = a;
+ len = args.length - 1;
+ }
+ for (var i = 0; i < len; i++)
+ url = url + "&arg=" + escape(args[i]);
+ url = url.replace( /[+]/g, '%2B'); // fix the unescaped plus signs
+ var xmlhttp = rs_init_object();
+ xmlhttp.open("GET", url, true);
+ xmlhttp.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
+ 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>