Creating a progress bar in CGI using Perl

Currently, everything is functioning correctly. However, the issue arises when trying to initiate the progress bar while sending emails.

I have encountered difficulties implementing various examples of progress bars in CGI.

The documentation available does not provide a clear understanding of how to implement a progress bar in CGI.

If anyone could assist me with the code above, it would greatly benefit my learning and allow me to grasp how the progress bar operates within CGI. This knowledge can be applied to my future projects.


#!/usr/bin/perl -w

use lib '.';
use strict;
use warnings;
use DBI;
use CGI;
use MIME::Lite;
use CGI::Carp qw(fatalsToBrowser);

my $q = new CGI();

my $host =   "localhost";
my $usr =    "root";
my $pwd =    "";
my $dbname = "tbl_users";

my $dbh = DBI->connect("DBI:mysql:$dbname:$host", $usr, $pwd, {
                                  AutoCommit => 0,
                                  RaiseError => 1, 
                                  }) or die $DBI::errstr;

my $sub = $q->param("sub");
my $msg = $q->param("msg");
my $success;

if ($sub) {
    my $getemails = $dbh->prepare("SELECT DISTINCT EMAIL FROM USERS");
    $getemails->execute();
    my $dbemails = $getemails->fetchall_arrayref;
    my $emails = join ',',map{$_->[0]}@$dbemails;

    my $to = '';
    my $from = '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="513f3e2334213d302811223825347f323e3c">[email protected]</a>';
    my $subject = $sub;
    my $message = "$msg";

    my $MSG = MIME::Lite->new(
                     From     => $from,
                     To       => $to,
                     Bcc      => $emails,
                     Subject  => $subject,
                     Data     => $message
                     );

    $MSG->send; 
    $success = "mail was sent successfully";

}

$dbh->disconnect || die "$DBI::errstr\n";

print "Content-type: text/html\n\n";

Answer №1

It seems there might be a misunderstanding of how Ajax functions here. Your current setup suggests that the Ajax call is repeatedly asking for your main CGI program, which may not yield the desired results. Ideally, the Ajax call should target a simpler program that can return a JSON response containing the necessary data for the main page.

Moreover, the underlying issues highlighted in our discussion back in February still persist. Your email sending process involves a single call to MIME::Lite::send(), meaning there is no real progress for the progress bar to track. The progress remains at 0% until the call and jumps to 100% upon completion.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

In HTML5, a full-width video exceeds the size of the screen

When I have a video set to full width in a header with the width at 100%, the issue arises with the height. The video is too large, causing the controls to be out of view unless I scroll. Is there a solution to remedy this problem? <video width="100%" ...

The payload transmitted from JavaScript to Django Views is devoid of any content

I'm currently working on sending data from JavaScript to Django using ajax. Below is the code snippet I am using for this: var json_name = {'name': 123} $.ajax({ method: 'POST', url: ...

Create a dynamic calendar by integrating dates with Javascript and an HTML table

Recently, I decided to delve into web design again and embark on a challenging project for my father's baseball business. The main task at hand is creating a detailed calendar using HTML tables. After spending a considerable amount of time perfecting ...

What is the process for sending an image as input to a Django view using an Angular frontend?

I currently have a django web api with an angular frontend that allows users to upload and view images. My goal now is to expand this functionality: when the user clicks the "segment" button (see image), it should send the corresponding image to my python ...

What are some techniques for animating SVG images?

Looking to bring some life to an SVG using the jQuery "animate" function. The plan is to incorporate rotation or scaling effects. My initial attempt with this simple code hasn't yielded the desired results: $("#svg").animate({ transform: "sc ...

AngularJS ng-onclick method sending value to Thymeleaf

I am facing an issue with the integration of Thymeleaf and AngularJS. Below is the Thymleaf page I have: <div ng-controller="ctrlsubcomment" > <div class="media" th:fragment="comments" th:each="newsComment : ${comments}"> <img ...

Combining data with MongoDB aggregate using two $group operations

My model is structured like this: { tokens: [ { value: { type: String, required: true, unique: true, }, origin: { type: String, default: 'Unknown', }, grabbedAt: { type: Date, default: Date.now, }, }, ], .. ...

modify the contents of a file stored on a distant server through ajax

Trying to update the content of the chatt.php file on the server using AJAX. $("#btnsend").click(function(){ var a = $("#write").val(); console.log(a); // prints value correctly $.ajax({ type: "POST", url: "ajax.php", d ...

Discover the magic of AngularJs autocomplete with a focus on exploring

I am currently utilizing autocomplete feature in my AngularJS application using NgAutocomplete module from . I would like to retrieve the continent of the selected city, but I'm not sure how to achieve this. Upon making a request, I receive a response ...

Converting a JSON PHP array into Javascript

How can I convert this PHP array named $data into JSON using json_encode? Whenever I try to do so in JavaScript by writing... var myJson = <?php echo json_encode($data) ?>; console.log(myJson); I encounter errors. I am curious about any restrictio ...

PHP Incrementing a Number without Defined Limit

I am facing an issue with the code provided below as it is throwing back an 'undefined' error for the countingNumbers variable. My objective is to incorporate the class name 'numbered' so that I can iterate over it in JavaScript and ass ...

Exploring the intricacies of nested objects

I am currently developing an API that retrieves data from an external source. After processing the business logic, I end up with the following response: { data: [ { BTC: { USD: 46389.84, RUB: 3406131.15, EUR: 39472.76, ...

What is preventing the hashmap from including duplicate values in its count in JavaScript?

Currently, I am attempting to tally the occurrences of objects in an array. The array in question has the following structure: [{ Title: 'Einstein', Author: 'Walter Isaacson' }, { Title: 'The Elegant Universe', Author: &apo ...

How to pass a data property as a function argument in Vue.js

Instead of using a few methods that are structured like this: showDiv1(){ this.showDiv1 = true }, showDiv2(){ this.showDiv2 = true } I am attempting to consolidate them into one method like so: showElements(...elementNames){ elementNames. ...

Protractor experiencing difficulty in adjusting price slider

As a newcomer to protractor, I am attempting to test a price slider that sorts products based on the provided price range. Unfortunately, I am facing difficulty in dragging the slider (min point) using protractor. Can anyone provide guidance on how to move ...

Using JavaScript and AJAX to manage and control a shell interface

Looking to create an HTML page that includes a YouTube video and utilizes JavaScript with the YouTube API. The objective is to embed a video and test if it has been fully downloaded using the YouTube API. I have set up an Apache server with MySQL and PHP ...

The Select element in angular fails to choose the intended option when tested with Cypress

I am encountering a challenge in my automation testing project where I need to select an option from a select element. The project is built using Angular and I am using Cypress for automation testing. As a newcomer to Cypress, I followed the instructions ...

What could be causing my webpage to fail after a refresh?

I am having an issue with my React app that is currently live on the web through HostGator. When I refresh the home page everything functions correctly, but if I try to refresh any other page, it displays a message saying the site does not exist and prompt ...

difficulty encountered when transmitting data via ajax to an express server

Just starting out with backend and ran into an issue when trying to send data using vanilla ajax to my express server. Can anyone spot where I might be making a mistake? Here is my ajax request: var xhttp = new XMLHttpRequest(); xhttp.onload ...

I am wondering why the content is not showing up when using state.map(foo => <>{foo}</>) in my code

Why does the first tsx code display the state.map properly while the second code displays nothing? Despite both pieces of code performing the same task in the same way, one list is correctly displayed while the other state.map has never rendered anything, ...