0

I have digital information written as Javascript variables by PHP into a .txt-File. This information gets changed by a user at a different interval.

var ISTUHSXDATE8 = '21.1.2018';
var ISTUHSXTIME8 = '20:11';
var ISTUHSXROT8 = 0;
var ISTUHSXGELB8 = 0;
var ISTUHSXGRUEN8 = 1; 
var ISTUHSXAUSLASTUNG8 = '0%';

To show actual information in the HTML body, it´s necessary to make the HTML document load the latest version of .txt from server. [At the moment handmade by push the button and in webprojekt by setInterval() automatically]

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="expires" content="0">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv='cache-control' content='no-cache'>
<script type="text/javascript" id="id_of_java_var"></script>
</head>
<body>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction() {
var dsts = new Date();
document.getElementById("id_of_java_var").src =
"https://www.juh-technik.de/StreifenstatusEA1.txt?time" + dsts.getTime();
}
</script>
</body>
</html>

With this code I can load latest version from the server for several .gif/.jpg/.html files by pushing the refresh button. The Problem is, this don´t works with .txt-files.

So my question is, how to refresh src of following line without page reload.

<script src="https://www.juh-technik.de/StreifenstatusEA1.txt" type="text/javascript" id="id_of_java_var"></script>

Thanks for your help :-)

12
  • I don't understand what the "bug" is. From your title, I first thought you meatn something along the line of setInterval() (w3schools.com/js/js_timing.asp), but the rest of the text is very confusing. Commented Feb 22, 2018 at 14:30
  • @Xan-Kun Clark-Davis, this code shows that bowser makes no refresh of txt-file. Here´s example at W3. w3schools.com/code/tryit.asp?filename=FOPMKYKWXNCK Missing Result by reload can be watched by Firefox-Console. (F12) Commented Feb 22, 2018 at 15:10
  • Cleaned up language to make this a little more clear. Commented Feb 22, 2018 at 15:21
  • I don't get any errors. The example works exactly as I would expect. Although I have no idea why you would want to set the "src" attribute in such a way. Commented Feb 22, 2018 at 17:39
  • AJAX might be want you are looking for. Commented Feb 22, 2018 at 17:42

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.