Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Why do I sometimes have problems loading or including a document from a URL (or whats this talk about async vs. synch)?

0
Posted

Why do I sometimes have problems loading or including a document from a URL (or whats this talk about async vs. synch)?

0

If you attempt to load an XMLDOM using the loadXML() method, the default behavior of the method is to load asynchronously. This means that the DOM starts loading, and immediately returns control to you. Unfortunately this means that you may attempt to use the DOM before it is loaded, resulting in annoying errors. There are two things you can do to prevent this situation. First, you can always tell the DOM to load synchronously (that is, wait for the document to finish loading before moving on to the next line of code) by setting the property async = False. This is how the load is accomplished in the code sample here. If you want the DOM to load asynchronously, you can always check to make sure that the property readyState = True before reading the DOM.

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.