My site stores strings in a json file and uses javascript to retrive value to HTML. Here's simplified version of the function.
HTML:
<html>
<head>
<script src="script.js"></script>
</head>
<body>
This is a demonstration. The author is:
<div>
<div class="author"></div>
</div>
</body>
</html>
Javascript:
request = new XMLHttpRequest();
request.open('GET', 'data.json', true);
request.onload = function () {
obj = JSON.parse(request.responseText);
obj.forEach(function (d) {
var el = document.createElement('p');
el.textContent = d.author;
document.getElementsByClassName('author')[0].appendChild(el);
});
};
request.send();
Json:
{
"author": "John Doe"
}
Implementation: http://embed.plnkr.co/Ixrz9R2KVLXpOqa7mwyU
The code doesn't return author name in the HTML. Is there anyway to do this without using jQuery if possible.