XMLDOM's Async property is paying attention to

xiaoxiao2021-03-05  27

The following DOM is the declared DOM object flag it is loaded. The readyState property can be read directly with Dom.ReadyState.

ReadyState is as follows

This attribute is read-only, and the return value may be below: 0-uninitialized: XML object is generated, but no file is loaded. 1-loading: The loader is in progress, but the file has not yet been analyzed. 2-loaded: Partial file has been loaded and parsed, but the object model has not taken effect. 3-Interactive: Only the loaded part of the file is valid, in which case the object model is valid but read-only. 4-Completed: The file is fully loaded, and the representative is successfully loaded.

Let's see what will happen when you create a DOM.

In LOAD, DOM's property readyState changes from 0 to 4 Each change, you can capture in the DOM onReadyStatechage event.

If you set DOM.ASYNC = True

The logo is asynchronous, that is, whether the LOAD event is executed or not, continue the following JS code.

If the later JS code is going to use DOM, it is troublesome, because it is not necessarily loaded, what should I do?

This uses the OnReadyStateChange event. Judging the readyState == 4 in this event to operate the DOM

DOM.ONREADYSTATECHAGE = function () {if (dom.readyState == 4) {// You write the code of the DOM action}}}

This is OK, which is the benefit of asynchronous: If the remote reflection is slow, it is not on the front desk.

If you set DOM.ASYNC = False, those that are all unused, JS will continue to do the following after Domload is completed. For the application that does not slowly, in particular calling the local server, you will do it directly.

转载请注明原文地址:https://www.9cbs.com/read-33897.html

New Post(0)