weixin_33743880 2015-07-16 23:58 采纳率: 0%
浏览 32

Javascript AJAX插入值

So I am making a site that shows the value of a .TXT file, this is what I got so far:

<script>
$(document).ready(function() {
 $("#responsecontainer").load("info.txt");

var refreshId = setInterval(function() {
  $("#responsecontainer").load('info.txt');
 }, 1000);
 $.ajaxSetup({ cache: false });
});
</script>

So it get's the string from info.txt and puts it inside the div resonsecontainer.

But now I want that same string to be in a value of a meter, and also a auto updater for that. The code is:

<meter id="cpumeter" value="60" min="0" max="120.47" title="GB">
<div class="meter-gauge">
<span style="width: 46.42%;"></span>
</div>
</meter>  

How do I autoupdate the value="60" to the string of the info.txt?

Thanks!

  • 写回答

1条回答 默认 最新

  • weixin_33727510 2015-07-17 00:03
    关注

    You can give a callback argument to .load(), and it will receive the contents of the file.

    $(document).ready(function() {
        function loadInfo() {
            $("#responsecontainer").load('info.txt', function(info) {
                $("#cpumeter").val(parseFloat(info));
            });
        }
        $.ajaxSetup({ cache: false });
        loadInfo();
        var refreshId = setInterval(loadInfo, 1000);
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助