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
18 my %initialized = ();#won't work if component is "preloaded"... so don't do that
20 <& /elements/rs_init_object.html &>
21 <& /elements/init_overlib.html &>
22 <SCRIPT TYPE="text/javascript">
24 % foreach my $func ( @{$opt{'subs'}} ) {
26 % next if $initialized{$key.$func}++;
29 % $furl =~ s/\"/\\\\\"/; #javascript escape (fix gvim syntax: ")
31 function <%$key%><%$func%>() {
32 // count args; build URL
33 var url = "<%$furl%>";
34 var a = <%$key%><%$func%>.arguments;
38 var content = 'sub=<% uri_escape($func) %>';
39 if ( a && typeof a == 'object' && a[0].constructor == Array ) {
44 len = args.length - 1;
46 for (var i = 0; i < len; i++)
47 content = content + "&arg=" + escape(args[i]);
48 content = content.replace( /[+]/g, '%2B'); // fix unescaped plus signs
50 if ( '<%$method%>' == 'GET' ) {
54 //alert('<%$method%> ' + url);
56 var xmlhttp = rs_init_object();
57 xmlhttp.open("<%$method%>", url, true);
59 xmlhttp.onreadystatechange = function() {
60 if (xmlhttp.readyState != 4)
63 if (xmlhttp.status != 200) {
64 if ( xmlhttp.status != 0 ) {
65 //not warning on the 0 errors, they pop up when navagating away
67 alert(xmlhttp.status + " status connecting to " + url);
70 var data = xmlhttp.responseText;
71 //alert('received response: ' + data);
72 if ( data.indexOf("<b>System error</b>") > -1 ) {
74 var end = data.indexOf('<a href="#raw">') - 1;
75 data = data.substring(0, end);
78 WIDTH, 480, MIDX, 0, MIDY, 0,
79 CAPTION, 'Error', STICKY, AUTOSTATUSCAP, DRAGGABLE,
80 CLOSECLICK, BGCOLOR, '#f00', CGCOLOR, '#f00'
83 //if ( w = window.open("about:blank") ) {
84 // w.document.write(data);
86 // // popup blocking? should use an overlib popup instead
87 // alert("Error popup disabled; try disabling popup blocking to see");
90 // invoke the callback
96 if ( '<%$method%>' == 'POST' ) {
98 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
99 xmlhttp.send(content);
103 xmlhttp.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
108 //rs_debug("x_$func_name url = " + url);
109 //rs_debug("x_$func_name waiting..");
118 my $url = $opt{'url'};
119 my $method = exists($opt{'method'}) ? $opt{'method'} : 'GET';
120 #my @subs = @{ $opt{'subs'};
121 my $key = exists($opt{'key'}) ? $opt{'key'} : '';
123 $url .= ( ($url =~ /\?/) ? '&' : '?' )