I have a web app that on button click initiates a script and populates the return value in a span, similar to below:
page.html
<button id="btn">Run function</button>
<span id="result_span">
<!--return value from doStuff goes here-->
</span>
<script>
document.getElementById("btn").addEventListener("click",init_function);
function init_function(){
console.log('init')
let updateLocation = document.querySelector('#result_span')
function onFailure(error){
let warning = `<span style="color:red">${error}</span>`;
updateLocation.innerHTML = warning;
};
function onSuccess(element){
let result = element;
updateLocation.innerHTML = result;
};
google.script.run.withFailureHandler(onFailure)
.withSuccessHandler(onSuccess)
.doStuff();
}
</script>
code.gs
function doStuff(){
//do stuff
return string;
}
This is working correctly, but how can I update the front end UI as the script runs. For example, something like:
function doStuff(){
//do stuff
update-the-user-part-one
//do more stuff
update-the-user-part-two
//do even more stuff
return string;
}
Unfortunately console.log('update-the-user-part-one') doesn't go the front end, but perhaps there is some way using callbacks or promise to have <span id="updates"></span> innerHTML update during the script.

element.innerHTML