调用远程服务器期间 php 内的基本加载器微调器

basic loader spinner inside php during call to remote server

我想在我的远程脚本处于 运行 并且我的前端页面处于 "waiting for ..." 状态时添加一个加载微调器。 我只有 1 php 页和一个 CSS 。 (目前仍在测试中,所以我还没有拆分脚本页面和 html 页面)。

我有以下 css 加载程序:

Style.css 编辑以替换“.”用“#”

#loader {
    border: 16px solid #f3f3f3; /* Light grey */
    border-top: 16px solid #3498db; /* Blue */
    border-radius: 50%;
    width: 120px;
    height: 120px;
    animation: spin 2s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

我的页面看起来像这样(清理后): 编辑 带有 webbm 评论

<!DOCTYPE html>
<html>
<head>
  <title> BETA APP HOME PAGE </title>
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
  <link rel="stylesheet" href="CSS/style.css">
</head>
<body>

<div id="loader"></div>

<?php
if (isset($_POST['STARTVISUREC']))
{

   echo '<script>console.log("End loader spinner")</script>';
// making appearing the spinner before the call to remote server. 
    echo '<script language="javascript">';
    echo 'document.getElementById("loader").style.display="inline"';
    echo '</script>';

// calling remote APP in BE server. 
$remotstarter = file_get_contents('http://192.168.56.154/WEBAPP/wa_start.php');

   echo '<script>console.log("End loader spinner")</script>';
// making disappearing the spinner after the call to remote is finished. 
    echo '<script language="javascript">';
    echo 'document.getElementById("loader").style.display="hidden"';
    echo '</script>';

}
if (isset($_POST['STARTFACEREC']))
{
// calling local script for other usage. 
shell_exec("sudo python  AppPy/cgi-bin/test.py");
echo("Off");
}
?>

<form method="post">
<button name="STARTVISUREC">START VISU REC</button>&nbsp;
<button name="STARTFACEREC">START FACE REC</button><br><br>
</form> 
<script>
</script>
</div>
</div>
<div style="margin-left:15%;padding:1px 16px;height:10px;">
</div>
</body>
</html>

仍然不正常加载微调器没有出现

对于您的具体情况,您可以 echo 一个脚本标签。

<?php
 echo '<script language="javascript">';
 echo 'document.getElementById("loader").style.display="inline"';
 echo '</script>';
?>

请注意,我调换了 "' 的用法。查看 echo 文档,了解为什么这是有用的 https://secure.php.net/manual/en/function.echo.php

我建议您查看 ajax 查询,它可以让您根据服务器响应在 javascript 中执行 javascript 操作。

这是一个基本示例:https://www.w3schools.com/php/php_ajax_php.asp