The front end gets the data of the .txt file and prints it

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>demo</title>
  </head>
  <body>
    <script>
      function readTextFile(file) {
          var rawFile = new XMLHttpRequest();
          rawFile.open("GET", file, false);
          rawFile.onreadystatechange = function () {
            if (rawFile.readyState === 4) {
              if (rawFile.status === 200 || rawFile.status == 0) {
                var allText = rawFile.responseText;
                console.log("获取到数据",allText);
              }
            }
          }
          rawFile.send(null);
        }
        window.onload = function () {
          readTextFile("../txt/1.txt");
        };
    </script>
  </body>
</html>

Guess you like

Origin blog.csdn.net/qq_43770056/article/details/131600561