Answer the question
In order to leave comments, you need to log in
How to update the text on the page using JS?
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no">
<title>GoDaemon</title>
<link href="/style.css" rel="stylesheet" type="text/css">
</head>
<body>
<div class="block">
<div class="cell">
<div class="center">
<div class="i">Key:</div>
<script type="text/javascript"><!--
document.write('')
//--></script>
</div>
</div>
</div>
</body>
</html>
Answer the question
In order to leave comments, you need to log in
<span class="fileData"></span>
var xhr;
setInterval(function(){
xhr&&xhr.abort();
xhr = new XMLHttpRequest();
//xhr.timeout = 3000; - изначально подумал я.
//Но ведь интервал может повториться раньше, когда браузеру в голову взбредет...
//Так что будем юзать abort
xhr.onreadystatechange = function(){
if(xhr.readyState == 4){
document.querySelector(".fileData").textContent = xhr.responseText;
}
}
xhr.open('GET', '/key', true);
xhr.send();
}, 3000);
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no">
<title>GoDaemon</title>
<link href="/style.css" rel="stylesheet" type="text/css">
</head>
<body>
<div class="block">
<div class="cell">
<div class="center">
<div class="i">Key:</div>
<script type="text/javascript">
function timeout() {
document.write('text')
}
setTimeout(timeout, 2000)
</script>
</div>
</div>
</div>
</body>
</html>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question