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);
    });
    
    评论

报告相同问题?