Synchronous XMLHttpRequest blocks earlier performed functions.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Haroldp
    New Member
    • May 2007
    • 3

    Synchronous XMLHttpRequest blocks earlier performed functions.

    Because I need to be sure that an Http Request is finished before other requests can be done I am using a synchronous XML Http Request.

    I want to show the text "loading... " on the page before the http-request starts. The strange thing here is that this "loading... " text is not visible on the page, but its method is performed though.

    If I place an "alert('somethi ng')" in between I do see the "loading... " on the page before the alert is popping up.

    How can I achieve to see the loading before the request instead of after the response of the request?

    Thanks in advance...

    Harold
  • dmjpro
    Top Contributor
    • Jan 2007
    • 2476

    #2
    Welcome to TSDN.

    where u putting the test Loading
    just send that code .....

    Comment

    • Haroldp
      New Member
      • May 2007
      • 3

      #3
      When clicked on the row element this must be performed:

      Code:
      row.onclick = function()
       (
      
              LoadingData("LoadingTable");
              passData = "SessionId=" + SessionId + "&Level=" + "User");
              var XMLResponse = SynchCall("wSetMainSelection", passData);
              OnResponse(XMLResponse.documentElement.childNodes[0].data);
       }

      The funcion SynchCall is as follows:

      Code:
      function SynchCall(method, passData)
      {
      
         //alert("no matter what");
         
          url = "http://" + location.host + "/project/webservice/Access.asmx/" + method;
          if (window.XMLHttpRequest) 
          {
              xmlhttp=new XMLHttpRequest();
          } 
          else 
          {
              xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");  
          }  
          if (xmlhttp) 
          {    
              xmlhttp.open("POST", url, false);
              xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
              xmlhttp.send(passData);
              return xmlhttp.responseXML;
          } 
          else 
          {
              alert("Not able to create HTTP request");
          }
      }
      You see that the alert is commented out. If I enable it, the LoadingData function will be performed.

      Comment

      • Haroldp
        New Member
        • May 2007
        • 3

        #4
        This code is more clear:

        When clicked on the row element this must be performed:

        Code:
        row.onclick = function()
         (
        
                LoadingData("LoadingDiv");
                passData = "SessionId=" + SessionId + "&Level=" + "User");
                var XMLResponse = SynchCall("wSetMainSelection", passData);
                OnResponse(XMLResponse.documentElement.childNodes[0].data);
         }
        
        LoadingData(div)
        {
          document.getElementById(div).innerHTML = "Loading...";
        }

        The function SynchCall is as follows:

        Code:
        function SynchCall(method, passData)
        {
        
           //alert("no matter what");
           
            url = "http://" + location.host + "/project/webservice/Access.asmx/" + method;
            if (window.XMLHttpRequest) 
            {
                xmlhttp=new XMLHttpRequest();
            } 
            else 
            {
                xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");  
            }  
            if (xmlhttp) 
            {    
                xmlhttp.open("POST", url, false);
                xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
                xmlhttp.send(passData);
                return xmlhttp.responseXML;
            } 
            else 
            {
                alert("Not able to create HTTP request");
            }
        }
        The LoadingData function will be performed always. You see that the alert is commented out. If I enable it the text "Loading... " will be shown.

        Comment

        Working...