-
Nov 5th, 2021, 12:40 PM
#1
Thread Starter
Member
[RESOLVED] script executing issue
So I am executing a XMLHttpRequest on button click. For some time, the user will not see any progress or status of the response.
The response may take awhile on receiving the reaponse.
How can we show to the user the progress or status of the request?
-
Nov 5th, 2021, 12:52 PM
#2
Re: script executing issue
Based on your design in this thread: https://www.vbforums.com/showthread....-you-loop-this
One option is to create a "status" element and then update the element's text as the code progresses, e.g.:
Code:
// <p id="status"></p> in your HTML
function loadXMLDoc() {
const status = document.getElementById('status');
const xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (xhttp.readyState !== 4 || xhttp.status !== 200 || !xhttp.responseText) {
status.innerText = 'Request failed';
loadXMLDoc();
return;
}
status.innerText = 'Request finished';
document.getElementById('p1').innerHTML = xhttp.responseText;
};
status.innerText = 'Request starting...';
xhttp.open("POST", "manage.php", true);
xhttp.send();
}
Alternatively it may be worth just showing/hiding a progress indicator like this: https://getbootstrap.com/docs/5.1/components/spinners/
-
Nov 5th, 2021, 12:57 PM
#3
Thread Starter
Member
Re: script executing issue
Originally Posted by dday9
Based on your design in this thread: https://www.vbforums.com/showthread....-you-loop-this
One option is to create a "status" element and then update the element's text as the code progresses, e.g.:
Code:
// <p id="status"></p> in your HTML
function loadXMLDoc() {
const status = document.getElementById('status');
const xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (xhttp.readyState !== 4 || xhttp.status !== 200 || !xhttp.responseText) {
status.innerText = 'Request failed';
loadXMLDoc();
return;
}
status.innerText = 'Request finished';
document.getElementById('p1').innerHTML = xhttp.responseText;
};
status.innerText = 'Request starting...';
xhttp.open("POST", "manage.php", true);
xhttp.send();
}
Alternatively it may be worth just showing/hiding a progress indicator like this: https://getbootstrap.com/docs/5.1/components/spinners/
yes progress indicator. been looking something like that. been from vb. net so i only know progressbar. thanks for the link and the snippet. gotta read that article now. thanks again dday.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|