Following up on what huck suggested, here is a demo to play with using Ajax. Change the file paths and urls to suit your web server.An html page
<html> <head><title>Example</title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jque +ry.min.js"> </script> <script> $(document).ready(function() { $(".update").click(function(){ var button = this; $.ajax({ type: 'POST', url: 'runme.cgi', data: { 'action': $(button).attr("id") }, success: function(res) { alert( res.msg ); var myIFrame = document.getElementById("dataDialog"); myIFrame.src = "runme.cgi?action=result"; }, error: function() { alert("Error : did not work"); } }); }) }) </script> </head> <body> <iframe id="dataDialog" src="about:blank"></iframe> <h2>Using Ajax</h2> <button class="update" id="update_1">Update 1</button> <button class="update" id="update_2">Update 2</button> <button class="update" id="update_3">Update 3</button> <button class="update" id="update_4">Update 4</button> </body> </html>
and the script runme.cgi
poj#!/usr/bin/perl use CGI; use JSON; use strict; my $logtext; my $logfile = 'c:/temp/web/update.log'; # somewhere writeable my $q = new CGI; my $action = $q->param('action'); if ($action =~ /update/){ # do stuff to update database sleep 1; open OUT,'>', $logfile or die "$!"; print OUT "Result of $action on\n".scalar(localtime)."\n"; print OUT "Line $_ message\n" for (1..rand(10)); close OUT; my $json = encode_json( { msg => "$action done" } ); # response print $q->header( -type => 'application/json' ),$json; exit; } if ($action eq "result"){ # get results of last update if (-e $logfile){ open IN,'<', $logfile or die "$!"; $logtext = do {local $/;<IN>}; close IN; } print $q->header( {-pragma =>'no-cache', -cache_control => "no-store,no-cache,must-revalidate"} ), $q->start_html, $q->pre($logtext),$q->end_html; exit; }
In reply to Re^5: send windowmessage from cgi back to form that called the cgi
by poj
in thread send windowmessage from cgi back to form that called the cgi
by tultalk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |