I am looking to keep a dialog open while data is being fetched from the server. Here is the code I have written:
(async()=>{
document.getElementById("dialog").showModal();
if(condition1 is true){
await server_call1();
}
if(condition2 is true){
await server_call2();
}
if(condition3 is true){
await server_call3();
}
document.getElementById("dialog").close();
})();
The server_call()
functions are all independent of each other. When I run this code, I keep getting an error in my console:
Uncaught (in promise) DOMException: Failed to execute 'showModal' on 'HTMLDialogElement': The element already has an 'open' attribute, and therefore cannot be opened modally.
Can someone help me resolve this issue? Thank you.
EDIT: Here is my html
:
<dialog id="dialog">
<p style="font-family: cursive;">Fetching results, please wait.. </p>
</dialog>