Newer
Older
2021-yuuji / fetch.html
@HIROSE Yuuji HIROSE Yuuji on 27 Aug 2021 663 bytes Add fetch() sample
<!DOCTYPE html>
<html lang="ja">
<head>
<title>fetch</title>
</head>
<body>
<h1>fetch</h1>
<p>ファイルを選んでね:
<select name="file">
 <option>aaa.txt</option>
 <option>iii.txt</option>
 <option>uu.txt</option>
</select>
</p>
<p><button type="button" id="load">読め!</button></p>
<pre id="pre"></pre>
<script type="text/javascript">
<!--
var file = document.getElementById("file"),
    load = document.getElementById("load"),
    pre  = document.getElementById("pre");
b.addEventListener("click", (e) => {
  fetch(file.value).then((r) => {
    return r.text;
  }).then((txt) => {
    pre.textContent = txt;
  });
});
// -->
</script>
</body>
</html>