-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
41 lines (40 loc) · 1.18 KB
/
index.html
File metadata and controls
41 lines (40 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<html>
<head>
<style>
li {
list-style-type: circle;
padding: 5px;
margin: 5px;
border: 2px solid red;
border-radius: 5px;
}
</style>
</head>
<body>
<div id="demo">
<h2>The XMLHttpRequest Object from File</h2>
<button type="button" onclick="loadDoc()">Load Document</button>
</div>
<div id="demo2"></div>
<script>
function loadDoc() {
const xhttp = new XMLHttpRequest();
xhttp.onload = function () {
var todolist = "<ul>";
var fileContent = this.responseText;
var textLines = fileContent.split("\n");
for (var i = 0, j = textLines.length; i < j; i++) {
var currentLine = textLines[i];
// for each line
var list = "<li>" + currentLine + "</li>";
todolist += list;
}
todolist += "</ul>";
document.getElementById("demo2").innerHTML = todolist;
}
xhttp.open("GET", "text_example.txt");
xhttp.send();
}
</script>
</body>
</html>