//Updates register table and redirects back to landing page for next steps.... async function stateRedirect() { //wait until you hear back from external server.... so put async // Then we repackage these variables into dataToSend... var dataToSend = {}; dataToSend.SubjectId = SubjectId; dataToSend.State = 7; // Now we send dataToSend to our amazing PHP script... var dataPromise = await fetch('../RecordState.php', { method: 'post', headers: {'Accept': 'application/json','Content-Type': 'application/json'}, body: JSON.stringify(dataToSend)}); // Finally, we can redirect the participant to the external task... var dataSentBack = await dataPromise.json(); var allIsWell = dataSentBack.allIsWell; if (allIsWell) { window.location.href = `https://do3.thinkcognito.org.uk/index.html?SubjectId=${SubjectId}`; } }