Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Case Analysis of JavaScript waiting for File

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the JavaScript waiting file case analysis of the relevant knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that everyone after reading this JavaScript waiting file example analysis article will have a harvest, let's take a look.

JavaScript waits for files

If you create a function to load external resources, such as scripts or files, you cannot use the content until it is fully loaded.

This is the best time to use callbacks.

This example loads a HTML file (mycar.html) and displays the HTML file in the web page after the file is fully loaded:

Wait for the file:

Function myDisplayer (some) {

Document.getElementById ("demo"). InnerHTML = some

}

Function getFile (myCallback) {

Let req = new XMLHttpRequest ()

Req.open ('GET', "mycar.html")

Req.onload = function () {

If (req.status = = 200) {

MyCallback (this.responseText)

} else {

MyCallback ("Error:" + req.status)

}

}

Req.send ()

}

GetFile (myDisplayer)

In the above example, myDisplayer is used as a callback.

The function (function name) is passed as an argument to getFile ().

This is the end of the article on "JavaScript waiting for file example analysis". Thank you for your reading! I believe you all have a certain understanding of the knowledge of "JavaScript waiting for document case analysis". If you want to learn more, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report