обновлять

This commit is contained in:
2021-06-08 19:00:37 +03:00
parent b051332fc0
commit 02af5fe730
3 changed files with 54 additions and 1 deletions

View File

@@ -0,0 +1,52 @@
function загрузитьJSONJS(отклик)
{
const запрос = new XMLHttpRequest();
запрос.onreadystatechange = function()
{
if (this.readyState == 4)
{
if (this.status == 200)
{
отклик(this.responseText);
}
else
{
console.error(this.status);
}
}
}
запрос.open("GET", "/json.js");// + "?" + gitjs.uuid());
запрос.send();
}
function исполнитьJSONJS(текст)
{
if (!текст.length)
{
return;
}
/*
try
{
console.debug("исполняем", текст);
eval(текст);
console.debug("исполнили", текст);
}
catch (e)
{
console.error(e);
}
*/
const скрипт = document.createElement("script");
скрипт.src = текст;
document.body.appendChild(скрипт);
console.debug("исполнили скрипт?", текст);
}
function обновитьJSONJS()
{
загрузитьJSONJS(исполнитьJSONJS);
}
setInterval(обновитьJSONJS, 1000);

View File

@@ -24,5 +24,6 @@
<script src="00130.платформы.js"></script>
<script src="01000.пуск.js"></script>
<script src="01300.пример.json.js"></script>
<script src="02000.обновление.js"></script>
</body>
</html>

View File

@@ -19,7 +19,7 @@ function process(req, res)
{
const content = Object.keys(jsonUpdates).sort().join("\n");
jsonUpdates = {};
res.writeHead(200);
res.writeHead(200, { "Content-Type": "text/javascript" });
res.end(content, "utf-8");
return;
}