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 <& /elements/rs_init_object.html &>
18 <& /elements/init_overlib.html &>
19 <SCRIPT TYPE="text/javascript">
21 % foreach my $func ( @{$opt{'subs'}} ) {
24 % $furl =~ s/\"/\\\\\"/; #javascript escape
29 function <%$key%><%$func%>() {
30 // count args; build URL
31 var url = "<%$furl%>";
32 var a = <%$key%><%$func%>.arguments;
36 var content = 'sub=<% uri_escape($func) %>';
37 if ( a && typeof a == 'object' && a[0].constructor == Array ) {
42 len = args.length - 1;
44 for (var i = 0; i < len; i++)
45 content = content + "&arg=" + escape(args[i]);
46 content = content.replace( /[+]/g, '%2B'); // fix unescaped plus signs
48 if ( '<%$method%>' == 'GET' ) {
52 //alert('<%$method%> ' + url);
54 var xmlhttp = rs_init_object();
55 xmlhttp.open("<%$method%>", url, true);
57 xmlhttp.onreadystatechange = function() {
58 if (xmlhttp.readyState != 4)
61 if (xmlhttp.status != 200) {
62 if ( xmlhttp.status != 0 ) {
63 //not warning on the 0 errors, they pop up when navagating away
65 alert(xmlhttp.status + " status connecting to " + url);
68 var data = xmlhttp.responseText;
69 //alert('received response: ' + data);
70 if ( data.indexOf("<b>System error</b>") > -1 ) {
72 var end = data.indexOf('<a href="#raw">') - 1;
73 data = data.substring(0, end);
76 WIDTH, 480, MIDX, 0, MIDY, 0,
77 CAPTION, 'Error', STICKY, AUTOSTATUSCAP, DRAGGABLE,
78 CLOSECLICK, BGCOLOR, '#f00', CGCOLOR, '#f00'
81 //if ( w = window.open("about:blank") ) {
82 // w.document.write(data);
84 // // popup blocking? should use an overlib popup instead
85 // alert("Error popup disabled; try disabling popup blocking to see");
88 // invoke the callback
94 if ( '<%$method%>' == 'POST' ) {
96 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
97 xmlhttp.send(content);
101 xmlhttp.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
106 //rs_debug("x_$func_name url = " + url);
107 //rs_debug("x_$func_name waiting..");
116 my $url = $opt{'url'};
117 my $method = exists($opt{'method'}) ? $opt{'method'} : 'GET';
118 #my @subs = @{ $opt{'subs'};
119 my $key = exists($opt{'key'}) ? $opt{'key'} : '';
121 $url .= ( ($url =~ /\?/) ? '&' : '?' )