Show "Waiting" on screen while action is in progress

Good day to all,
i’m a newby with Yii framework and PHP.
I call a SQL Stored Procedure with a button; query caller in is controller, while button is in the form; when action is terminated, calling setFlash, i show a message for the user; i would like to show a message also before the action start, or immediately after, something like “Waiting action…”, but i can not.
I try to use beforeAction() or afterAction(), but only “Action done” message appears when action is terminated; i try also with setFlash() and hasFlash(), but the message appears only when action is terminated, two messages in this case, “Waiting” and “Done”.
There is a way to intercept the button pressed in the form and show message “Waiting” ?
Thanks

Yes. AJAX.

I look for documentation and i found everythinks; i try somethink, but i cannot understand what i have to do. In form i have this button:

Blockquote
<?php echo Html::a(’ Backup database’,
[‘backupdb’], [‘class’ => ‘btn btn-warning btn-lg’]); ?>

In controller there is function:

Blockquote
function actionBackupdb($Filepath)
{
try
{
$SqlProcedure = “exec DBBACKUP ‘$Filepath’”;
$SqlProcedureCommand = Yii::$app->db->createCommand($SqlProcedure);
$SqlProcedureCommand->query();
}
catch (Exception $e)
{
$e->rollback();
Yii::$app->session->setFlash(‘error’,'Backup database error: '.$e->getMessage());
return $this->redirect(Yii::$app->request->referrer);
}
if (file_exists($Filepath))
{
Yii::$app->session->setFlash(‘success’, ‘Backup database done.’);
}
else
{
Yii::$app->session->setFlash(‘warning’,‘Backup database failed.’);
}
return $this->redirect(Yii::$app->request->referrer);
}

I try to change button with submitButton and call function in controller, but i have the same result.
What is the best way to show setFlash with waiting message, starting function and then show setFlash with result message ?
Thanks

I have tried some solutions, but it don’t works; i have tried with another view, popup, some js code, but the problem remains: when controller action begin its job, the view don’t update itself, only when the action is terminated.
The last code on controller:

    public function actionBeforedbmaintenance($dbaction)
    {
        Yii::$app->session['dbAction'] = $dbaction;
        Yii::$app->session['isWaiting'] = true;
        Yii::$app->session->setFlash('WaitFileStat');

         return $this->redirect(Yii::$app->request->referrer);
     }

    public function actionDbmaintenance($dbaction)
    {
         Yii::$app->session['isWaiting'] = false;
        Yii::$app->session['dbAction'] = 'none';
        Yii::$app->session->removeFlash('WaitFileStat');

        switch ($dbaction)
        {
            case "FileStatDB":
                 $this->Test('DB');
                break;

            case "FileStatLOG":
                  $this->Test('DB');
                break;

        }
    }

    public function Test($type)
    {
        for ($mul = 1; $mul <= 100000000; ++$mul);

        Yii::$app->session->setFlash('success', Yii::t('app', 'Test done.'));

        return $this->redirect(Yii::$app->request->referrer);
    }

on view

    <?php if (Yii::$app->session->getFlash('WaitFileStat')) { ?>

        </br>

        <h1 style="text-align: center; color: red;"><?= Yii::t('app', 'Waiting...') ?></h1>

        <?php 

            $dbaction = Yii::$app->session['dbAction'];

            switch (Yii::$app->session['dbAction'])
            {
                case 'FileStatDB':
                    
                    Yii::$app->session['isWaiting'] = false;
                    Yii::$app->runAction('maintenance/dbmaintenance', ['dbaction' => $dbaction]);
                    break;

                case 'FileStatLOG':
                    
                    Yii::$app->session['isWaiting'] = false;
                    Yii::$app->runAction('maintenance/dbmaintenance', ['dbaction' => $dbaction]);
                    break;

                default:
                    Yii::$app->session['isWaiting'] = false;
                       
            }
        ?>

    <?php } else { ?>

        <?php echo Html::a('<i class="fas fa-info"></i>'.'  '.Yii::t("app", "DB file status"), 
                        ['beforedbmaintenance', 'dbaction' => 'FileStatDB'], ['class' => 'btn btn-info btn-lg']); ?>

        <?php echo Html::a('<i class="fas fa-info"></i>'.'  '.Yii::t("app", "Log file status"), 
                        ['beforedbmaintenance', 'dbaction' => 'FileStatLOG'], ['class' => 'btn btn-info btn-lg']); ?> 

I also try to use “target = _blank”, but after i have one more tab opened on browser.
I don’t like that the user press one of the buttons, backup or reindex on database begin, and the view remains without warning to wait the end of operation.
At the moment i have no more idea.
Can anyone help me ?