Results 1 to 3 of 3

Thread: [RESOLVED] script executing issue

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2021
    Posts
    38

    Resolved [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?

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,760

    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/
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  3. #3

    Thread Starter
    Member
    Join Date
    Oct 2021
    Posts
    38

    Re: script executing issue

    Quote Originally Posted by dday9 View Post
    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
  •  



Click Here to Expand Forum to Full Width