bigup401 has asked for the wisdom of the Perl Monks concerning the following question:

is there anyway way to submit something in CGI without reloading the page. I mean when you do post and get the page has to take action. but is there any way you can perform action and page don't reload. like how it works in php. without using any mojo or dancer or Catalyst

Replies are listed 'Best First'.
Re: cgi page reload
by marto (Cardinal) on Nov 09, 2018 at 10:18 UTC

      thanks

Re: cgi page reload
by Anonymous Monk on Nov 09, 2018 at 10:36 UTC
    > like how it works in php This is not how it works in php

      am looking at use CGI::Ajax and I see its useful to me. it works for me

      it was explanation example. am trying it now and i see the examples now. this is wat i wanted

Re: cgi page reload
by harangzsolt33 (Deacon) on Nov 10, 2018 at 00:01 UTC
    If your web page needs to send something small (less than 1KB of data) back to the server, you could do it by loading an image. The image url could contain an encoded data.

    www.yourwebsite.com/cgi-bin/servebmp.cgi?saveThis=askldajlkdjasldkjaslkjasdljaslkas

    And when you load the image, your perl script on the other end could decode the url and store the data. Oh, and when it's done, it should send back an image. perhaps a 1x1 bmp image. It has the smallest header:

    ############################################################### # # This function creates a simple B/W bitmap image # to send back to the browser as a response. # # Usage: SpitBMP(width, height) # # Example: SpitBMP(4, 3) ---> Creates a black 4x3 BMP image # sub SpitBMP { my $W = @_ ? shift : 1; my $H = @_ ? shift : 1; $|++; my $HEADERLEN = 62; my $DATASIZE = Ceil($W * $H / 8); my $FILESIZE = $DATASIZE + $HEADERLEN; my $BITS_PER_PIXEL = 1; my $HEADER = 'BM' . pack('VxxxxVVVV', $FILESIZE, $HEADERLEN, 40, $W, + $H) . chr(1) . pack('xCxxxxxV', $BITS_PER_PIXEL, $DATASIZE) . "\0" x + 20 . "\xFF\xFF\xFF\0"; my $OUTPUT = $HEADER . "\0" x $DATASIZE; print "Content-Type: image/bmp\n" . 'Content-Length: ' . length($OUTPUT) . "\n\n" . $OUTPUT; } ############################################################### # # Rounds a number up to the nearest integer. # # Usage: INTEGER = Ceil(FLOAT) # sub Ceil { my $DEC = shift; my $INT = int($DEC); return $INT if ($DEC - $INT == 0); return $INT + 1 if ($DEC > 0); return $INT - 1; }