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 :-)

  • I don't understand what the "bug" is. From your title, I first thought you meatn something along the line of `setInterval() ` (https://www.w3schools.com/js/js_timing.asp), but the rest of the text is very confusing. – Xan-Kun Clark-Davis Feb 22 '18 at 14:30
  • @Xan-Kun Clark-Davis, this code shows that bowser makes no refresh of txt-file. Here´s example at W3. https://www.w3schools.com/code/tryit.asp?filename=FOPMKYKWXNCK Missing Result by reload can be watched by Firefox-Console. (F12) – Daniel Stappenbeck Feb 22 '18 at 15:10
  • Cleaned up language to make this a little more clear. – Jon B Feb 22 '18 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. – Xan-Kun Clark-Davis Feb 22 '18 at 17:39
  • AJAX might be want you are looking for. – Xan-Kun Clark-Davis Feb 22 '18 at 17:42
  • @JonB, Thanks for cleanup language. It was not in detail what I´m looking for, but after re-cleanup I hope it´s more clear. – Daniel Stappenbeck Feb 23 '18 at 09:00
  • @Xan-KunClark-Davis : I choosed this way to refresh the global var from external Script by Javascript of HTML-File. Do you have a smarter solution for me? Maybe based on AJAX? – Daniel Stappenbeck Feb 23 '18 at 09:01
  • If you can, rename your .txt as .js this might help. EDIT: The problem is that your server return a `text/plain` Content-Type. The browser will not evaluate the Javascript in this case. – ChrisR Feb 23 '18 at 09:04
  • @ChrisR, sounds good. I´ve a html form send by post to php and php writes the StreifenstatusEA1.txt-File with form-filled information. I was not successfull by advise PHP to write .js-files. (only .csv, .html and .txt-files) – Daniel Stappenbeck Feb 23 '18 at 09:08
  • @ChrisR, the browser is able to understand the global var and works with them without problems (Tested FF, IE, Chrome). Just the refresh is not working. – Daniel Stappenbeck Feb 23 '18 at 09:10
  • @ChrisR, do you think the `text/plain` Problem might get solved by add `` to `StreifenstatusEA1.txt`-file? At the Moment i`ve no possibility to try, wait for sunday :-( – Daniel Stappenbeck Feb 23 '18 at 09:51
  • ok seems it´s not possible to refresh `src` of ` – Daniel Stappenbeck Feb 24 '18 at 20:39

0 Answers0