I am trying to read a text file from folder where website is saved.
File is in the same folder as a class from which I try to read the file.
config.json (file which I am trying to read) contains:
{
"DATE": "Datum"
}
My code:
function loadFile(filePath) {
var result = null;
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", filePath, false);
xmlhttp.send();
if (xmlhttp.status==200) {
result = xmlhttp.responseText;
}
return result;
}
var myStuff = loadFile("config.json");
console.log(myStuff);
output
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Dispečink</title>
<link href='https://fonts.googleapis.com/css?family=Roboto:400,500,700' rel='stylesheet' type='text/css'>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
</head>
<body>
<div id="root"></div>
<script type="text/javascript" src="/static/js/bundle.js"></script></body>
</html>
My problem is that I am getting output which i do not expect.
How to get correct data from config.json?
I have tryed to insert nonsensical path to loadFile() but still getting the same output