Question

DHTML Page doesn't refresh (NOT Reload question!) objects ...

Asked by: deadstone_270668

Hi all,

I have a page that calls a script to send an XML doc (using XML HTTP Request) with a systemid to a backend service page that uses the systemid in a query on the db, then retrieves data from a log table, and sends the data back in the XML response back to the client - where it is loaded dynamically into a table.

So, all well and good, works fine.

My problem is that there is no refresh of the window after the user has clicked 'LOad Data' and before the 'SendRequest' is run

Thing is, I have a nice 'Please Wait' div all set up and looking nice, but even though I call 'divPleaseWait.style.display = "block"' before the code to run the xml send, it still only displays AFTER the xml response has come back from the server.

Here is my code:
window.divPleaseWait.style.display = "block";
      
// set up the screen, put the elements in the right places!
window.document.body.style.cursor="wait";
window.status="importing...";

window.history.forward(1);
divPleaseWait.style.left = ((document.body.offsetWidth -
divPleaseWait.offsetWidth) / 2);
                              
divPleaseWait.style.top = ((document.body.offsetHeight -
divPleaseWait.offsetHeight) / 2);

divFinished.style.left = ((document.body.offsetWidth -
divFinished.offsetWidth) / 3);
                              
divFinished.style.top = ((document.body.offsetHeight -
divFinished.offsetHeight) / 2);

var oFundsData, sFundsDataVal
        
// create a new XML Doc object  
var oXML = new ActiveXObject("Microsoft.XMLDOM");
 
// set props
oXML.async=false;
oXML.resolveExternals = false;
        
// create the root element
var oRoot=oXML.appendChild(oXML.createElement("Request"));
        
// set the attribute to determine which table to update
oRoot.setAttribute("system", sSystem);
      
Isloaded = SendRequest(oXML)
      
if (Isloaded==true)
      {
      alert("Import successful");
      }
      else
      {
      alert("Import failed")
      }
                  
      document.all("divPleaseWait").style.display = "none";
      document.all("divFinished").style.display = "none";
      window.document.body.style.cursor="default";
      window.status="Ready";
      }
      
      }

<<< END CODE <<<<

Here is the <BODY> code with the divPleaseWait in it...
>>> CODE>>>
<BODY>
      
<table border="0" cellspacing=1 width="100%">
  <tr>
      <td width="100%">
      <p style="MARGIN-LEFT: 0px; MARGIN-RIGHT: 0px" align="left"
     ><b><font color="#00309c" face="Tahoma" size="5">Import
      </font></b><b><font color="#00309c" face="Tahoma" size="5">System Data</font></b></p></td>
  </tr>
</table>
<hr color="#00309c" size="1">

<DIV ID = LoadBtns name = "LoadBtns" style= "DISPLAY: block">

<table id = tblBtns name = "tblBtns">
      <tr>
            <td>
                  <BUTTON id=btnLoadiFASTData name=btnLoadiFASTData ACCESSKEY="i" onclick='ShowBusy("iFAST")'>Load <u>i</u>FAST Data</BUTTON>      
            </td>      
            <td>
                  <BUTTON id=btnLoadMCHData  name=btnLoadMCHData ACCESSKEY="M" onclick='ShowBusy("MCH")'>Load <u>M</u>CH Data</BUTTON>      
            </td>
            </tr>

</table>

<DIV LANGUAGE=javascript id=divPleaseWait name = "divPleaseWait"
style="BORDER-RIGHT: buttonhighlight 2px outset; BORDER-TOP: buttonhighlight 2px outset; DISPLAY:
      none; FONT-SIZE: 8pt; Z-INDEX: 4; FILTER: progid:DXImageTransform.Microsoft.dropshadow(OffX    
        =2, OffY=2, Color='gray', Positive='true'); LEFT: 342px; BORDER-LEFT: buttonhighlight 2px outset;
      WIDTH: 350px; CURSOR: default; BORDER-BOTTOM: buttonhighlight 2px outset; FONT-FAMILY: Tahoma; POSITION: absolute; TOP: 260px; BACKGROUND-COLOR: buttonface" align=center>

      <DIV LANGUAGE=javascript onselectstart= "window.event.returnValue=false;" style="PADDING-RIGHT: 3px; PADDING-LEFT: 3px; FONT-WEIGHT: bolder; PADDING-BOTTOM: 3px; CURSOR:
            default; COLOR: captiontext; PADDING-TOP: 3px; BORDER-BOTTOM: white 2px
            groove; BACKGROUND-COLOR: activecaption"  id  = divImportCaption name="divImportCaption">
            Importing Selected Data
      </DIV>

      <DIV LANGUAGE=javascript onselectstart= "window.event.returnValue=false;" style="PADDING-RIGHT: 5px; PADDING-LEFT: 5px; PADDING-BOTTOM: 5px; CURSOR: default; PADDING-TOP: 5px">
            Please wait while the data is imported.
      </DIV>
      <DIV LANGUAGE=javascript onselectstart= "window.event.returnValue=false;" style="PADDING-RIGHT: 5px; PADDING-LEFT: 5px; PADDING-BOTTOM: 5px; CURSOR: default; PADDING-TOP: 5px">
            This may take several seconds.
      </DIV>
      <DIV LANGUAGE=javascript onselectstart= "window.event.returnValue=false;" style="PADDING-RIGHT: 5px; PADDING-LEFT: 5px; PADDING-BOTTOM: 5px;
            CURSOR: default; PADDING-TOP: 5px">
            <marquee width="50%" bgcolor=white > Please be patient... </marquee>
      </DIV>
      
</DIV>

<DIV style="DISPLAY: none" name="divResults" id="divResults">
            <TABLE id = tblImpResults name = "tbtImpResults" width="100%" border=0 style="CURSOR: default; BORDER-BOTTOM: #6699ff 1px outset">
            <font face="Tahoma" size="1">
              <tr class="TableTitle" >
                  <TH noWrap Style = "BORDER-BOTTOM: #6699ff 1px outset" width="15%">LoadTime</TD>
                  <TH noWrap Style = "BORDER-BOTTOM: #6699ff 1px outset" width="40%">SourceFile</TD>
                  <TH noWrap Style = "BORDER-BOTTOM: #6699ff 1px outset" width="20%">Comment</TD>
                  <TH noWrap Style = "BORDER-BOTTOM: #6699ff 1px outset" width="7%">Rows Read</TD>
                  <TH noWrap Style = "BORDER-BOTTOM: #6699ff 1px outset" width="8%">Rows Loaded</TD>
                  <TH noWrap Style = "BORDER-BOTTOM: #6699ff 1px outset" width="10%">Rows Archived</TD>              
              </tr></TR></TR></TR>
             
            </TABLE>
            </DIV>
      

</DIV></FONT>


</BODY>
<<< END CODE <<<

so, why does IE wait till the response comes back from the server before updating the page, even though I set the divPleaseWait style.display to "block" BEFORE any other code runs?

Even the cursor doesn't change till AFTER the function call has completed!

It's really strange, as the status bar text changes, but the divPleaseWaiy remains hidden, till after the results table has displayed.

thx for any help or tips

Philip

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2003-09-05 at 06:02:09ID20730048
Tags

refresh

,

page

,

reload

,

dhtml

,

objects

Topic

JavaScript

Participating Experts
4
Points
500
Comments
27

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. CSS-P: Opera + Mozilla margins and padding (erroneou…
    I am trying to write my site in XHTML 1 + CSS 2 and have taught myself by reading widely including W3C specs. Most of the problems I experience seem to be browser non-compliance, if I read the specs correctly, but even though (as an ex-test analyst) I reckon I am good at int...
  2. DIV padding/margin settings
    I having a bit of a problem with my website, mainly the padding/margin of a <div>. if you take a look at http://www.bluehatmedia.co.uk/spanishproperty/ you will notice in the blue text area at the bottom if I add padding to the div to the left it expands the layout of ...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: mingshuoPosted on 2003-09-05 at 06:26:02ID: 9295645

This is a timing problem. You can test it by placing an ALERT statement (to make the script pause) after displaying the DIV and before the http send request. The DIV will show up.

To make this work you need to use ASYNC = TRUE mode, calling another function after the XML has loaded that hides the loading message.

Try something like

        oXML.async = true;
        oXML.onreadystatechange = ProcessLoading;

.....

    function ProcessLoading()
        {
                    if (oXML.readyState == 4)
                       {
                       alert("XML has been loaded. Place code to hide your loading message here...");
                       }

         }


Make sure that the function you are calling has access to the variables of the caller function, ie. make it a subfunction of the caller function.

Hope this helps,
Mingshuo

 

by: NushiPosted on 2003-09-05 at 06:28:41ID: 9295668

you have to check teh state of the Response.

>> why does IE wait till the response comes back from the server before updating the page
when using XMLHttpRequest the
you have to assign orReadyStateChange function;
there are 4 staets to this object 4==page /reuest loaded.
The IE waits beacuse of that.

mean while im going over your code to see if there are any other issues.

Nushi

 

by: deadstone_270668Posted on 2003-09-05 at 06:44:40ID: 9295788

Hi,

thanks for your comments. But I think you misunderstand.

it's not a problem AFTER the xml has been returned from the server.

The problem is BEFORE. It doesn't take the time to execute the 'divPleaseWait.style.display="block";' and 'BODY.style.cursor="wait";' until afterwards.

In my code I call 'document.all("divPleaseWait").style.display="block";' right at the beginning after the user has clicked the button, however, the div does not show on in IE till after the server has completed...

I need the 'Please wait' div to be displayed before the xml is created and xmlhttprequest is called, stay on screen till the response comes back, then I can hide it after building the results table from the xmlhttp response object.

I tried putting the alert after the divPleaseWait change display code, and that worked, but again, clicking ok on this leaves the message box on the screen till the table is built using the xmlhttp response.

it seems that IE just doesn't take time to update the pages, but goes straight on ...

Here is my entire client-side scrpt:

>>>> CODE >>>>
<script language=javascript >

function SendRequest(requestXMLDoc)
      {
// this function receives an XML DOM Document from the calling function.
// it loads posts it using HTTP to the backend service page '_Funds_action.asp'
// http://<%= sPath %>
      var retvalue;
      var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      xmlhttp.Open("POST", "ImportData.asp", false);
      
      xmlhttp.Send(requestXMLDoc);
      
      //document.write(xmlhttp.xml)
      //alert(xmlhttp.xml)
      //alert(xmlhttp.responseText);
             
      if (xmlhttp.status==200)
      {
            var xmlResponseDoc = xmlhttp.responseXML;
            //xmlhttp.responseXML menthod returns the persistable XML document sent from the
            //the server using the .save method of XMLDOM objects(xmldoc.save(response)),but
            //it requires the.asp page generating the response to set its MIME type
            //(Response.ContentType) to "text/xml",otherwise it won't parse the response
            //correctly and      xmlResponseDoc.parseError.errorCode will always be 0,also
            //xmlResponseDoc.xml will always be empty string ""
            //Alternatively,we can create a new instance of Microsoft.XMLDOM,and load the
            //response as xml string text from xmlhttp.responseText.For this,the .asp page
            //generating the response is not required to set its MIME type to "text/xml",
            //and it can parse any response sent by response.write() in the .asp page.
            //But this approach might encounter Unicode encoding(UTF-8,UCS-2,..) conversion problems.
            if ((xmlResponseDoc.parseError.errorCode == 0) && (xmlResponseDoc.xml !=""))
            {
                  var oResponseRoot = xmlResponseDoc.documentElement;
                  var ActionStatus = oResponseRoot.getAttribute("actionstatus");
                  var iRecs = oResponseRoot.getAttribute("records");
                              
                  if((ActionStatus == null) || (iRecs == null))
                  {
                        alert("Required data missing from response message.");
                        retvalue = false;
                  }
                  else
                  {
                        switch (ActionStatus)
                        {
                              case "success":retvalue = true;
                                    BuildResultsTable(oResponseRoot)
                                    break;
                              case "failed":retvalue = false;
                                                  alert(oDescription.text);
                                                  break;
                              default:alert("Response action status invalid.");
                                      retvalue = false;
                        }
                  }
            }
            else
            {
            alert("Response message is not well formed XML.");
              retvalue = false;
            }
      }
      else
      {
            alert("Backend service page unreachable or not working correctly.");
            retvalue = false;
      }
return retvalue;
}

function ShowBusy(sSystem)
      {
      document.all("divPleaseWait").style.display = "block";
      
      // set up the screen, put the elements in the right places!
      window.document.body.style.cursor="wait";
      window.status="importing...";
      
      //window.history.forward(1);
      divPleaseWait.style.left = ((document.body.offsetWidth -
      divPleaseWait.offsetWidth) / 2);
                              
      divPleaseWait.style.top = ((document.body.offsetHeight -
      divPleaseWait.offsetHeight) / 2);
      
      LoadData(sSystem)

      document.all("divPleaseWait").style.display = "none";
      window.document.body.style.cursor="default";
      window.status="Ready";            
      }

function LoadData(sSystem)
      {

      // call the Import ASP page, but in a Modal window that will
      // close as soon as the HTTP stream starts being written on
      // the server! So while the import is running server-side,
      // the DataLoad.htm will show the nice 'Please Wait'
      // DIV dialog. Then when the ASP Response is finished, and the
      // HTTP starts coming onto IE on the client - the Window_Onload
      // event will run, set up the screen of the calling page (ImportSysIDsWait.htm !)
      // and immediately close itself!

      // NOTE: XML 3 used here
      var oFundsData, sFundsDataVal
        
      // create a new XML Doc object  
      var oXML = new ActiveXObject("Microsoft.XMLDOM");
        
      // set props
      oXML.async=true;
      oXML.resolveExternals = false;
        
      // create the root element
      var oRoot=oXML.appendChild(oXML.createElement("Request"));
        
      // set the attribute to determine which table to update
      oRoot.setAttribute("system", sSystem);
      
      Isloaded = SendRequest(oXML)
      
      if (Isloaded==true)
            {
            alert("Import successful");
            }
      else
            {
            alert("Import failed")
            }

      }

function BuildResultsTable(xmlRoot)
      {
      // the DocumentELement of the xmlhttp Response object is passed in,
      // so navigate it and build a table...
      
      var nodes=xmlRoot.childNodes;
      var oTable = document.all("tblImpResults")
      
      // loop through the entire xml doc, and for each node, add a new row to the table
      for (x=0; x<nodes.length; x++)
            {
            var y = xmlRoot.childNodes.item(x)
            var oRow
            oRow = oTable.insertRow();
            
            // for each childnode, add a new cell to the table
            for (chiNode=0; chiNode< y.childNodes.length; chiNode++)
                  {
                  var oCell = oRow.insertCell();
                  oCell.innerText = y.childNodes(chiNode).text;
                  oCell.face = "Tahoma";
                  oCell.style.fontSize="10";
                  }            
            }
            document.all("divResults").style.display="block"      
            return;
      }
      
</script>
<<<< END CODE <<<

function ShowBusy is called by the 'button' click.
function LoadData is called by 'ShowBusy', but AFTER the div should be displayed.
function 'SendRequest' is called by function LoadData to send the rquest to the back-end service page using xmlhttp request

then after the server finishes and returns a xml response object conbtaining the results,

function 'BuildResultsTable' uses the xml object to data to dynamically  build a table.

finally the code returns to ShowBusy to hide the divPleaseWait and show a 'Finished' dialog


thanks for your help and investigation...

Philip

 

by: NushiPosted on 2003-09-05 at 06:58:39ID: 9295876

hi again:

instead of if (Isloaded==true)    {

use the
onreadystatechange to hide your div.

Nushi.

 

by: NushiPosted on 2003-09-05 at 07:01:08ID: 9295898

i have posted the last comment before your last comment.
so im looking over your new code now.

Nushi.

 

by: deadstone_270668Posted on 2003-09-05 at 07:05:40ID: 9295937

ok, I tried changing it like this, but still the div won't display untill AFTER (as opposed to before, and also I get a Type Mismatch due to the function call of ProcessLoading

function LoadData(sSystem)
      {

      // call the Import ASP page, but in a Modal window that will
      // close as soon as the HTTP stream starts being written on
      // the server! So while the import is running server-side,
      // the DataLoad.htm will show the nice 'Please Wait'
      // DIV dialog. Then when the ASP Response is finished, and the
      // HTTP starts coming onto IE on the client - the Window_Onload
      // event will run, set up the screen of the calling page (ImportSysIDsWait.htm !)
      // and immediately close itself!

      // NOTE: XML 3 used here
      var oFundsData, sFundsDataVal
        
      // create a new XML Doc object  
      var oXML = new ActiveXObject("Microsoft.XMLDOM");
        
      // set props
      oXML.async=true;
      oXML.resolveExternals = false;
      
      oXML.onreadystatechange= ProcessLoading(oXML, sSystem)
      }

function ProcessLoading(oXML, sSystem)
      {
      if (oXML.readyState == 4)
            {
          // Hide divs and change window.status
             
            // create the root element
            var oRoot=oXML.appendChild(oXML.createElement("Request"));
                    
            // set the attribute to determine which table to update
            oRoot.setAttribute("system", sSystem);
      
            Isloaded = SendRequest(oXML)
      
            if (Isloaded==true)
                  {
                  alert("Import successful");
                  }
            else
                  {
                  alert("Import failed")
                  }
            }      
      }

 

by: deadstone_270668Posted on 2003-09-05 at 07:29:11ID: 9296115

sorry, not entirely familiar with the idea of 'subfunction' ...

still fairly new to JavaScript.

if I use another function, I must ensure that the other function has access to the variables of the calling function right?

so should I use module-level variables? Or is there a way of passing in the variables like this:

oXML.onreadystatechange= ProcessLoading(oXML, sSystem)
     }

function ProcessLoading(oXML, sSystem)
    {
    if (oXML.readyState == 4)
         {
....


thx

Philip
if I do this I get an error msg...

 

by: deadstone_270668Posted on 2003-09-05 at 07:35:22ID: 9296166

BTW, the comments at the beginning of the 'LoadData' function are rubbish, and meaningless...

 

by: mingshuoPosted on 2003-09-05 at 07:46:13ID: 9296255

what I meant with subfunction was nesting 2 functions like

function LoadXML()
    {
    ....
     oXML.async = true;
     oXML.onreadystatechange = ProcessLoading;

         function ProcessLoading()
           {
                   if (oXML.readyState == 4)
                      {
                      alert("XML has been loaded. Place code to hide your loading message here...");
                      }

            }

    }

This way you are sure the inner function has access to the outer/its parent function.

What error do you get? It works fine for me...

Mingshuo

 

by: mingshuoPosted on 2003-09-05 at 07:50:27ID: 9296292

PS: do not use a function with the name "LoadXML" (as I did in the example above) since this is a predefined function! Just give it a different name...

 

by: deadstone_270668Posted on 2003-09-05 at 07:55:27ID: 9296338

yep, I got that in the end...

trouble is, when I do this, the code within the if(oXML.readyState == 4) ... never runs...

very strange! I must have some kind of weird XML error, here is the code within my 'LoadData' function :

      // create a new XML Doc object  
      var oXML = new ActiveXObject("Microsoft.XMLDOM");
        
      // set props
      oXML.async=true;
      //oXML.resolveExternals = false;
      
      oXML.onreadystatechange = ProcessLoading;

    function ProcessLoading()
          {
          alert("Process Loading!");
           if (oXML.readyState == 4)
                   {
            // create the root element
            var oRoot=oXML.appendChild(oXML.createElement("Request"));
               
            // set the attribute to determine which table to update
            oRoot.setAttribute("system", sSystem);
      
            Isloaded = SendRequest(oXML)
      
            if (Isloaded==true)
                  {
                  alert("Import successful");
                  }
                  else
                  {
                  alert("Import failed")
                  }

//                 alert("XML has been loaded. Place code to hide your loading message here...");
                 }

           }              

      }

>>> END CODE >>>>

so you see, it is nested.

but we NEVER see the 'alert("Process Loading!");' alert box!

it just

 

by: deadstone_270668Posted on 2003-09-05 at 07:58:10ID: 9296366

I need to emphasize that before nesting it worked, but the page would not refresh and show the 'divPleaseWait' until AFTER the response xml comes back from the server.

wheras now, with this nesting, I get nothing

increased points ...

 

by: deadstone_270668Posted on 2003-09-05 at 08:03:14ID: 9296419

BTW, I am using IE 5.5, and I (hope) I am using XML 3 on a Windows 2000 Professionsl workstation...

 

by: mingshuoPosted on 2003-09-05 at 08:11:31ID: 9296486

Sorry, you misunderstood me. The OUTER function needs to do the loading, the INNER function is called only if the state of the http request changes. It it changes to state 4, this means that the xml finally loaded and that you can hide your loading message. (In IE there are several other states that will be called before it reaches 4=loaded, so don't place code before readyState==4)


function myFunctionLoadingXmlThroughHttp()
   {
   ....
    oXML.async = true;
    oXML.onreadystatechange = CheckLoadingStatus;
   
    var success = oXML.load(filename);
    if (!success) alert("XML file not found or not correctly formatted!");


        function CheckLoadingStatus()
          {
                  if (oXML.readyState == 4)
                     {
                     alert("XML has been loaded. Place code to hide your loading message here...");
                     }

           }

   }


Hope this clears is up,
Mingshuo

 

by: deadstone_270668Posted on 2003-09-05 at 08:26:25ID: 9296610

let's be clear here,

the xml does not load anything, it's simply a way of sending the system id to the back-end service page using XML HTTP POst instead of asp, although it is in fact an ASP page on the back end server that does the work - running the stored procedure on the server, then returns an XML doc in the Response object. I then use that to create a results table, showing which files have been loaded into the table, how many records were read, discarded, and how many archived.

so really, there is no actual XML doc loading done on the client, until the response is sent back by the server.

Now, while that is going on, I want that divPleaseWait showing on the screen.

Unfortunately, even when I put that alert box u suggested in your first coment, yes, it shows, but when I click <OK> on that alert box, well, once again there is a type of IE hangup or memory leak that stops all further action till the response object comes back from the server...

anyway, here is the new LoadData(sSystem) function, with the nested function 'CheckLoadingStatus' as you suggested.

>>> CODE >>>>
function LoadData(sSystem)
      {

      // call the Import ASP page, but in a Modal window that will
      // close as soon as the HTTP stream starts being written on
      // the server! So while the import is running server-side,
      // the DataLoad.htm will show the nice 'Please Wait'
      // DIV dialog. Then when the ASP Response is finished, and the
      // HTTP starts coming onto IE on the client - the Window_Onload
      // event will run, set up the screen of the calling page (ImportSysIDsWait.htm !)
      // and immediately close itself!

      // NOTE: XML 3 used here
      var oFundsData, sFundsDataVal
      
      // create a new XML Doc object  
      var oXML = new ActiveXObject("Microsoft.XMLDOM");
        
      // set props
      oXML.async=true;
      oXML.onreadystatechange = CheckLoadingStatus;
             
      // create the root element
      var oRoot=oXML.appendChild(oXML.createElement("Request"));
        
      // set the attribute to determine which table to update
      oRoot.setAttribute("system", sSystem);
      
      function CheckLoadingStatus()
            {
        if (oXML.readyState == 4)
            {
            alert("XML has been loaded. Place code to hide your loading message here...");
            }
        }      
       
      Isloaded = SendRequest(oXML)
      
      
      if (Isloaded==true)
            {
            alert("Import successful");
            }
      else
            {
            alert("Import failed")
            }

      }

<<<< END CODE <<<

but despite all this, we still cannot get around this kind of IE hangup or timing issue or whatever, very weird and frustrating...

makes me wanna go back to good ole ASP/HTML forms! let the users have a blank page for 30 seconds while the ASP does it's work on the server after a form post and then 20 seconds for the HTTP stream to be written back to the IE client...mad mad mad :))

cheers, I hope you can help me

Philip

 

by: deadstone_270668Posted on 2003-09-05 at 08:47:31ID: 9296782

I am becomming certain this is a bug in IE 5.5 ...

I know that JS / JavaScript look at all the var decs in a function prior to executingcode, which of course means that the XML DOM Document is instantiated BEFORE the code to set the DIV !

But still, it shouldn't hang up like that.

Has anyone managed to get that DIV to display after the button is pressed, and before anything else is done?

 

by: mingshuoPosted on 2003-09-05 at 08:48:35ID: 9296791

>
>    // create the root element
>    var oRoot=oXML.appendChild(oXML.createElement("Request"));
>      
>    // set the attribute to determine which table to update
>    oRoot.setAttribute("system", sSystem);
>    
....
>    Isloaded = SendRequest(oXML)
   
1.
If you are simply sending an ID to the server, why don't you use something like (replacing the lines above):

    var Isloaded = oXML.load(filename+"?id=" + id);

Depending on the ID it gets throught the http get vars, the ASP page returns the corresponding XML file. This should do what you want, without sending an http request.

2.
I am not sure what you use "oRoot" for. But if you really need to send an http request, make it a separate object (not a child of your xml data).

        objSrvHTTP = new ActiveXObject("Msxml2.XMLHTTP.4.0");
       
3.
If possible, update to MS XML Core Services 4.0 and use

var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.4.0");


Mingshuo

 

by: mingshuoPosted on 2003-09-05 at 08:51:20ID: 9296809

PS: filename = URL

 

by: AcklenXPosted on 2003-09-05 at 14:11:59ID: 9298908

just a random note ( mostly cause i'm lazy and don't have time at the moment )....

if you split your script into two pieces that can maintain variable scope between them, you can use a setTimeout() to get around the sill javascript thread locking problem.  just call the second script (the part you want to execute after) using the setTimeout() and give it a 0 ms delay.

i appologize since this is probably way off track and won't helps since i haven't taken a good look at any of the comments... but i figured with no solution after some lengthy exchanges, it may be worth my two cents

good luck

 

by: makcPosted on 2003-09-06 at 13:58:07ID: 9302556

QUOTE:

My problem is that there is no refresh of the window after the user has clicked 'LOad Data' and before the 'SendRequest' is run

Thing is, I have a nice 'Please Wait' div all set up and looking nice, but even though I call 'divPleaseWait.style.display = "block"' before the code to run the xml send, it still only displays AFTER the xml response has come back from the server.

EOQ.

RESOLUTION:

obvious. set display = "block" when user clicks "LOad Data", and then use setTimeout to wait enough untill page refreshes (that's usually 100...500 msecs), and when timeout elapses, go "run xml send" or whatever.

 

by: makcPosted on 2003-09-06 at 14:06:21ID: 9302602

That is:

Here is my code:
window.divPleaseWait.style.display = "block";

setTimeout("Voila()", 500)

function Voila()
{
   
// set up the screen, put the elements in the right places!
window.document.body.style.cursor="wait";
window.status="importing...";

window.history.forward(1);
divPleaseWait.style.left = ((document.body.offsetWidth -
divPleaseWait.offsetWidth) / 2);
                       
divPleaseWait.style.top = ((document.body.offsetHeight -
divPleaseWait.offsetHeight) / 2);

divFinished.style.left = ((document.body.offsetWidth -
divFinished.offsetWidth) / 3);
                       
divFinished.style.top = ((document.body.offsetHeight -
divFinished.offsetHeight) / 2);

var oFundsData, sFundsDataVal
     
// create a new XML Doc object  
var oXML = new ActiveXObject("Microsoft.XMLDOM");
 
// set props
oXML.async=false;
oXML.resolveExternals = false;
     
// create the root element
var oRoot=oXML.appendChild(oXML.createElement("Request"));
       
// set the attribute to determine which table to update
oRoot.setAttribute("system", sSystem);
   
Isloaded = SendRequest(oXML)
   
if (Isloaded==true)
    {
    alert("Import successful");
    }
    else
    {
    alert("Import failed")
    }
             
     document.all("divPleaseWait").style.display = "none";
    document.all("divFinished").style.display = "none";
    window.document.body.style.cursor="default";
    window.status="Ready";
    }
   
     }

}
<<< END CODE <<<<

 

by: makcPosted on 2003-09-06 at 14:07:35ID: 9302612

oh, damn, looks like  AcklenX was first -((

 

by: deadstone_270668Posted on 2003-09-08 at 03:37:02ID: 9308462

Monday !

ok, that at least shows the screen updates. But now I get an error 'Object expected' at line 1 (line 1 ?)

here is my procedure:
>>>> CODE >>>>
function ShowBusy(sSystem)
      {
      // set up the screen for Busy!

      window.document.body.style.cursor="wait";
      window.status="importing...";
      window.history.forward(1);

      //LoadData(sSystem);

      window.divPleaseWait.style.display = "block";

      setTimeout("Voila()", 500)

            function Voila()
            {
               
            // set up the screen, put the elements in the right places!
            // create a new XML Doc object  
            var oXML = new ActiveXObject("Microsoft.XMLDOM");

            // set props
            oXML.async=false;
            oXML.resolveExternals = false;
                 
            // create the root element
            var oRoot=oXML.appendChild(oXML.createElement("Request"));
                 
            // set the attribute to determine which table to update
            oRoot.setAttribute("system", sSystem);
               
            Isloaded = SendRequest(oXML)
               
            if (Isloaded==true)
               {
               alert("Import successful");
               }
               else
               {
               alert("Import failed")
               }
                         
            document.all("divPleaseWait").style.display = "none";
            document.all("divFinished").style.display = "none";
            window.document.body.style.cursor="default";
            window.status="Ready";
            }
        
      }


<<< END CODE <<<<

any idea's why I should suddenly get that - is there a probkem with the nested 'Voila' function?

thanks to everyone for their excellent help with this BTW !

Philip

 

by: makcPosted on 2003-09-08 at 03:51:18ID: 9308510

I don't think you can nest that. I thought that was plain code for <script> tag.
also, if you reference oXML, oRoot, etc from other places, remove all "var"s from Voila() body.

 

by: makcPosted on 2003-09-08 at 04:32:29ID: 9308659

so, the code should be as:

<script>
.....

var oXML, ..., oRoot; // declare as global just in case

function ShowBusy(sSystem)
{
   ......
    window.divPleaseWait.style.display = "block";

    setTimeout("Voila()", 500)
  ........
}

function Voila()
{
 .... ( no "var" here) ....
}

.....

</script>

 

by: makcPosted on 2003-09-08 at 04:35:52ID: 9308682

also, 500 msec is time that was required for IE some very complex data-bound pages.
my guess, 100 will be more than enought for you ;)

you may also try 0, but if it is really fires immediately (???), there's a chance .display="none" will get executed before .display="block" will take effect. or there is no chance. try it.

 

by: deadstone_270668Posted on 2003-09-08 at 05:36:04ID: 9309007

excellent, it works fine now.

still worried about the fact of the thread-locking - it stops me from using a nice 'Please be patient' filter transition that changes colours, but hey - that's IE, and we're just gonna have to trust Microsoft on that one!

all points awarded for A+ help from everyone.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...