HTML - Display text from a text file
Posted: Wed Feb 23, 2011 11:34 pm
In html, is there any way to display some text from a given text file on a webpage? Thanks!
Sharing, Teaching and Supporting coders of all ages and levels since 2009
https://www.codenstuff.com/forum/
<html>
<head>
</head>
<body>
<textarea id="text"></textarea>
<script>
var req = new XMLHttpRequest();
req.open("GET", "file.txt", false);
req.send();
var textarea = document.getElementById("text");
textarea.innerText = req.responseText;
</script>
</body>
</html>
Cheatmasterbw wrote:In html, is there any way to display some text from a given text file on a webpage? Thanks!Looks like mandai's got you covered, however let me remind you that html is a markup language (Hence Hypertext Markup Language) if you're unaware of what that means, just Google it, and you should findout.
Cheatmasterbw wrote:is there a way to make it display no text if there is an error?Yes you can check the status code with req.status.