Sfoglia il codice sorgente

обновлять

master
parent
commit
02af5fe730
3 ha cambiato i file con 54 aggiunte e 1 eliminazioni
  1. +52
    -0
      02000.обновление.js
  2. +1
    -0
      index.html
  3. +1
    -1
      сервер.js

+ 52
- 0
02000.обновление.js Vedi 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);

+ 1
- 0
index.html Vedi 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>

+ 1
- 1
сервер.js Vedi 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;
}


Loading…
Annulla
Salva