So I have an express server configured to send the below html page upon request:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="../style.css">
<title>My Title</title>
</head>
<body >
<div id="state">
<p></p>
</div>
<script>
const urlParams = new URLSearchParams(window.location.search);
const dateparam = urlParams.get('date');
function loadDoc() {
fetch('http://my_machine_name:5000/wa/send/api?date=' + dateparam).then(response => response.json()).then(post => {
document.getElementById("state").innerHTML = post.htmltext;
const interv = setInterval(loadState, 1000);
});
}
function loadState() {
fetch('http://CLINIC:5000/api/update').then(response => response.json()).then(post => {
document.getElementById("state").innerHTML = post.htmltext;
if (post.finished) {
clearInterval(interv);
};
});
}
window.onload = "loadDoc()"
</script>
</body>
</html>
here is the node js code to send the html page:
app.get('/wa', function (req, res) {
const report = req.query.report;
if (report) {
res.sendFile(path.join(__dirname, '/report.html'));
console.log('report requested')
}
else {
res.sendFile(path.join(__dirname, '/send.html'));
}
});
Every thing works fine, except when I refresh the report html page, when I do that nothing happens, and in fact a request is never made to the server, and when I examine the network tab of the developer's tool in chrome I see a request for this URL 'http://my_machine_name:5000/wa/send/api?date=2021-1-1&report=true', with pending status, so the request is correct, I don't understand why it is not transfered to the server? If however I cancel the refresh and press enter on the address bar the request is sent and every thing works fine once more, so it is just a refresh thing. I'm testing this on my local windows server machine if that matters.
Thank you very much.