Internet Explorer also lets you track the progress of an XML document as it's being loaded. In particular, you can use the onreadystatechange and ondataavailable events to watch what's happening. The readyState property in the onreadystatechange event informs you about the current status of a document. Here's an example showing how this works: Listing ch07_09.html<HTML> <HEAD> <TITLE> Handling document loading events </TITLE> <SCRIPT LANGUAGE="JavaScript"> var xmldoc function loadDocument() { xmldoc = new ActiveXObject("microsoft.XMLDOM") xmldoc.ondataavailable = dataAvailableHandler xmldoc.onreadystatechange = stateChangeHandler xmldoc.load('ch07_01.xml') } function dataAvailableHandler() { messageDIV.innerHTML += "Status: data available.<BR>" } function stateChangeHandler() { switch (xmldoc.readyState) { case 1: messageDIV.innerHTML += "Status: data uninitialized.<BR>" break case 2: messageDIV.innerHTML += "Status: data loading.<BR>" break case 3: messageDIV.innerHTML += "Status: data loaded.<BR>" break case 4: messageDIV.innerHTML += "Status: data loading complete.<BR>" if (xmldoc.parseError.errorCode != 0) { messageDIV.innerHTML += "Status: error.<BR>" } else { messageDIV.innerHTML += "Status: data loaded alright.<BR>" } break } } </SCRIPT> </HEAD> <BODY> <CENTER> <H1> Handling document loading events </H1> </CENTER> <CENTER> <INPUT TYPE="BUTTON" VALUE="Load the document" ONCLICK="loadDocument()"> </CENTER> <DIV ID="messageDIV"></DIV> </BODY> </HTML> The results of this Web page appears in Figure 7-7, and you can see the progress that Internet Explorer made in loading a document in that page. Figure 7-7. Monitoring XML loading events in Internet Explorer.
|