Показать сообщение отдельно
  #2 (permalink)  
Старый 16.11.2018, 10:03
Аватар для SuperZen
Профессор
Отправить личное сообщение для SuperZen Посмотреть профиль Найти все сообщения от SuperZen
 
Регистрация: 08.11.2017
Сообщений: 641

схематично как-то так:
index.html
<script>
  const Process = function () {
    var count = 1
    var bs = []
    return {
      req1: async () => {
        var a = await fetch('http://localhost:2999/get1.php')
        var a_r = await a.text()
        if (parseInt(a_r) === 1) {
          var intervalId = setInterval(async () => {
            count++
            var b = await fetch('http://localhost:2999/get2.php')
            var b_r = await b.text()
            bs.push(b_r)
            if (count > 5) {
              console.log(count, bs)
              clearInterval(intervalId)
            }
          }, 500)
        }
      }
    }
  }

  const instance = new Process();
  instance.req1()

</script>


get1.php
<?php
echo '1';


get2.php
<?php
echo '2';
Ответить с цитированием