#!/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 $/;}; 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; }