in reply to Re^3: send windowmessage from cgi back to form that called the cgi
in thread send windowmessage from cgi back to form that called the cgi

Enough of this. I will ser a global variable as a flag and "watch" it in javascript on the html page. When it changes I request the form to load into the iframe.

  • Comment on Re^4: send windowmessage from cgi back to form that called the cgi

Replies are listed 'Best First'.
Re^5: send windowmessage from cgi back to form that called the cgi
by poj (Abbot) on Mar 15, 2017 at 07:38 UTC

    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

    #!/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; }
    poj
Re^5: send windowmessage from cgi back to form that called the cgi
by huck (Prior) on Mar 15, 2017 at 02:05 UTC

    You should just loaded the cgi-bin call into the iframe rather than the main page in the first place.

      And indeed it is working fine as you suggested. Couldn't see the trees for the forest, so to speak. Thanks loads. Best regards