5 include( '/elements/xmlhttp.html',
7 'url' => $p.'misc/something.html',
8 'subs' => [ 'subroutine' ],
11 'method' => 'GET', #defaults to GET, could specify POST
12 'key' => 'unique', #unique key
17 <SCRIPT TYPE="text/javascript">
19 function rs_init_object() {
22 A=new ActiveXObject("Msxml2.XMLHTTP");
25 A=new ActiveXObject("Microsoft.XMLHTTP");
30 if(!A && typeof XMLHttpRequest != "undefined")
31 A = new XMLHttpRequest();
33 alert("Can't create XMLHttpRequest object");
37 % foreach my $func ( @{$opt{'subs'}} ) {
40 % $furl =~ s/\"/\\\\\"/; #javascript escape
45 function <%$key%><%$func%>() {
46 // count args; build URL
47 var url = "<%$furl%>";
48 var a = <%$key%><%$func%>.arguments;
52 var content = 'sub=<% uri_escape($func) %>';
53 if ( a && typeof a == 'object' && a[0].constructor == Array ) {
58 len = args.length - 1;
60 for (var i = 0; i < len; i++)
61 content = content + "&arg=" + escape(args[i]);
62 content = content.replace( /[+]/g, '%2B'); // fix unescaped plus signs
64 if ( '<%$method%>' == 'GET' ) {
68 //alert('<%$method%> ' + url);
70 var xmlhttp = rs_init_object();
71 xmlhttp.open("<%$method%>", url, true);
73 xmlhttp.onreadystatechange = function() {
74 if (xmlhttp.readyState != 4)
77 if (xmlhttp.status != 200) {
78 alert(xmlhttp.status + " status connecting to " + url);
80 var data = xmlhttp.responseText;
81 //alert('received response: ' + data);
83 if ( data.indexOf("<b>System error</b>") > -1 ) {
85 if ( w = window.open("about:blank") ) {
86 w.document.write(data);
88 // popup blocking? should use an overlib popup instead
89 alert("Error popup disabled; try disabling popup blocking to see");
95 if ( '<%$method%>' == 'POST' ) {
97 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
98 xmlhttp.send(content);
102 xmlhttp.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
107 //rs_debug("x_$func_name url = " + url);
108 //rs_debug("x_$func_name waiting..");
117 my $url = $opt{'url'};
118 my $method = exists($opt{'method'}) ? $opt{'method'} : 'GET';
119 #my @subs = @{ $opt{'subs'};
120 my $key = exists($opt{'key'}) ? $opt{'key'} : '';
122 $url .= ( ($url =~ /\?/) ? '&' : '?' )