簡體   English   中英

使用javascript從文本文件獲取價值

[英]Get value from a text file using javascript

我有一個文本文件,其中包含一個值,該值會隨着時間的推移而更新,但這沒關系,我要使用javascript從.txt文件中獲取此值,然后在獲得該值時,我想將當前的變量值從.txt文件更改為該新值。 因為一次只有一個值(例如1或10),所以只需要在.txt文件中獲取該值即可,而不需要特定的值。

到目前為止,我的javascript / html:

<div class="curVariable">
Cur variable: <span id="curVar"></span>
</div>

<script type="text/javascript"> 

var curVar= 1;
document.getElementById("curVar").innerHTML = curVar;

</script>

假設文件在服務器上,請使用以下jQuery代碼:

   $(document).ready(function() {
    $("#butt").click(function() {
        $.ajax({
            url : "helloworld.txt",
            dataType: "text",
            success : function (data) {
                $(".text").html(data);
            }
        });
    });
}); 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM