使用JS刷新页面的一部分

时间:2015-03-05 12:32:24

标签: javascript jquery ajax html5

我无法使用Jquery更新我的标签。它应该在我的页面上每秒后更新但没有任何反应。我的javascript有问题吗?

基本上我想做的是每秒更新标签。但不知何故,这是行不通的。有人可以帮帮我吗?

您可以在下面找到我的2个文件的代码:

////////////// Index.html://///////////////

<!--AWP_IN_Variable Name='"webdata".AmountOfErrors' -->

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
   <title>Gebr. Gerrits Recycling Helmond</title>
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   <link href="css/default.css" rel="stylesheet" type="text/css"/>

   <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
   <script src="http://code.highcharts.com/highcharts.js"></script>
   <script src="/js/jquery.min.js"></script>
   <script src="/js/highcharts.js"></script>
</head>
<body>
    <div class="Maindiv">
        <div class="header">
           <img src="images/gerritslogo800.jpg" class="Logo">   
        </div>

        <div class="content">
        <br/>
        <table>
        <tr>
            <th>Part</th>
            <th>Value</th>
        </tr>
        <tr>
            <td>Ferro:</td>
            <td>0 kg</td>
        </tr>   
        <tr>
            <td>Non-Ferro:</td>
            <td>0 kg</td>
        </tr>
        <tr>
            <td>Errors:</td>
            <td><label id="amountOfErrors" name="amountOfErrors">:="webdata".AmountOfErrors:</label></td>
        </tr>
        </table>
        </div>  
<script type="text/javascript">
    $(document).ready(function()
    {
        //query the amountOfErrors variable every second
        $.ajaxSetup({ cache: false });
        setInterval(function() 
        {
            $.get("IOamountOfErrors.htm", function(result)
            {
                $('#amountOfErrors').text(result);
            });
        },1000);
    });
</script>
       <div class="footer">
           Gebr. Gerrits Metaalhandel Helmond B.V. <br/>
           Gebr. Gerrits Metaalrecycling B.V. <br/>
           Auto Verschrotings Industrie "A.V.I." Den Bosch B.V. <br/>
           Euregio Recycling B.V.<br/>      
       </div>
    </div>
</body>
</html>

////////////// IOamountOfErrors.htm://///////////////

&LT; ! - AWP_IN_Variable Name ='“webdata”.AmountOfErrors' - &gt; := “的Webdata” .AmountOfErrors: (在'&lt;'和'!'之间添加了空格,否则它不会显示此网站上的代码)

已经在网上搜索过:我实际上发现了我需要的东西,但对我来说它不起作用:https://www.dmcinfo.com/latest-thinking/blog/id/8567/siemens-s7-1200-web-server-tutorial--from-getting-started-to-html5-user-defined-pages

请帮帮我!

提前致谢,

巴特

2 个答案:

答案 0 :(得分:0)

我最好的是你正在调试这个本地而不是网络服务器吗?

因为您的javascript正在尝试执行不适用于file://

的跨源请求

编辑:

你能试试这段代码吗?

<script type="text/javascript">
    $(document).ready(function()
    {
        //query the amountOfErrors variable every second
        setInterval(function() 
        {
            $.post("IOamountOfErrors.htm", function(result)
            {
                $('#amountOfErrors').text(result);
            });
        },1000);
    });
</script>

答案 1 :(得分:0)

要更新标签,您可以使用setInterval。这是可能有用的代码

var count = 20;
function myFunction() {
    setInterval(function(){  startCounter() }, 1000);
}
$("#counterStart").click(function(e){
    myFunction();
});
 function startCounter() {
    $("#counter").text(count);
 }

HTML:

<input type="button" value="counter" id="counterStart"  />
<span id="counter">dfsdfs </span>

工作FIDDLE

相关问题