схематично как-то так:
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';