So i have text file which contains some numbers and i want so display all that content in html page. I assume i need to use javascript or jQuery. I tried things like:
function getText() {
fetch('inputfile.txt')
.then(function(res) {
return res.text();
})
.then(function(data) {
console.log(data);
});
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<html>
<head>
<title></title>
<style type="text/css" media="screen">
</style>
<script type="text/javascript" src="jquery-1.11.3.min.js"></script>
<script type="text/javascript">
$(function() {
$.get('inputfile.txt', function(data) {
//If the returned data is not empty or whitespace
if (data) {
// split the string into several strings when a new line occures
var lines = data.split('\n'); // Take note of the \n This is the new line character also known as a line ending, end of line (EOL), or line break.
// If there are more than 0 lines
if (lines.length > 0) {
// For every line console.log out what the line is with the line number prepended.
for (var i = 0; i < lines.length; i++) {
console.log(i + ": " + lines[i]);
}
}
} else {
// It is empty, do somethin else
alert('no data present in txt file.');
}
});
});
</script>
</head>
<body>
</body>
</html>
But every time i check webpage it not showing any content from txt file.