首页 > 解决方案 > 如何从标签中获取价值并将其价值每秒增加 1?

问题描述

我正在做一个 ajax 调用,例如返回一个 40:12:59 的字符串。该字符串带有一个已经缠绕在其周围的 td 。

我怎样才能从那里开始数秒?

我还可以返回完整的时间戳(例如 1564061259)并从那里开始工作。但最后,我需要像上面指定的日期格式。

我要显示数据的页面的 Ajax 调用:

    <div id="result"></div>

<script>

function load_data()
{
    $.ajax({
        url:"_overview.php",
        method:"POST",
        success:function(data)
        {
            $('#result').html(data);
        },
        complete: function(){
        $('#loading-image').hide();
        }
    });
}

load_data()

</script>

检查第 7 行。这是我打算在前端每秒增加一的值。这个文件(“_overview.php”)是我提出请求的文件。

<?php
include '../../variables.php';
include '../../_Database.php';
$db = Database::getInstance();



        echo '    <table class="table" style="zoom: 1;">';
        echo '        <thead class="thead-dark">';
        echo '            <tr>';
        echo '                <th scope="col">Auftrag</th>';
        echo '                <th scope="col">Artikel</th>';
        echo '                <th scope="col">Voraussichtliches Ende</th>';
        echo '                <th scope="col">Stillstand</th>';
        echo '                <th scope="col">Einrichtzeit</th>';
        echo '                <th scope="col">Avg TPP</th>';
        echo '                <th scope="col">Auftragsstart</th>';
        echo '                <th scope="col">Laufzeit</th>';
        echo '            </tr>';
        echo '        </thead>';
        echo '        <tbody>';

        $result = mysqli_query($db->link, "SELECT * FROM `Workorder` WHERE isLocked = 0");
        while ($row = mysqli_fetch_assoc($result))
        {   

            $wo = $row['idWorkOrder'];
            $article = $db->getArticle($wo);
            $articleString = $db->getArticleString($db->getArticle($wo));
            $db->getAllTimeStamps($wo);
            $estimatedCompletion;
            $estimatedCompletionFormatted;
            if ($db->getEstimatedCompletion($wo) == 0)
            {
                $estimatedCompletionFormatted = "no data";
            }
            else
            {
                $estimatedCompletion = $db->getEstimatedCompletion($wo) + time();
                $estimatedCompletionFormatted = date('Y-m-d -  H:i:s', $estimatedCompletion);
            }

            $machinePerformance = $db->machinePerformance($wo);
            $machinePerformance = ($machinePerformance - 100) * - 1;

            $configPerformance = $db->getConfigPerformance($wo);
            $configPerformance = ($configPerformance - 100) * - 1;

            $avgTimePerPiece = $db->calculateAverageTimePerPieceTotal($wo);
            $firstTimeStamp = $db->getFirstTimeStamp($wo);
            $start = date('Y-m-d -  H:i:s', $firstTimeStamp);

            $mostRecentTimeStamp = $db->getMostRecentTimeStamp($wo);
            $timeInProduction = $mostRecentTimeStamp - $firstTimeStamp;

            $timeInProductionFormatted = floor($timeInProduction / 3600) . 
            gmdate(":i:s", $timeInProduction % 3600);


            echo '            <tr>';
            echo '                <td>'. $wo .'</td>';
            echo '                <td>'.$articleString.'</td>';
            echo '                <td>'.$estimatedCompletionFormatted.'</td>';
            echo '                <td>'.$machinePerformance.'%</td>';
            echo '                <td>'.$configPerformance.'%</td>';
            echo '                <td>'.(int)$avgTimePerPiece.'</td>';
            echo '                <td>'.$start.'</td>';
            echo '                <td>'.$timeInProductionFormatted.'</td>';
            echo '            </tr>';
        }

    echo '        </tbody>';
    echo '    </table>';

?>

标签: javascript

解决方案


您可以使用setInterval()更新秒数,然后创建更多函数来触发分钟和小时的更改。


推荐阅读