I'm facing an issue with my code. It works perfectly on my computer, but when I move it to the server, I encounter the following error.
Error: Uncaught SyntaxError: expected expression, got '<'
Here is the code snippet causing the problem:
setInterval(function () {
loadJSON(function (response) {
jsonresponse = JSON.parse(response);
document.getElementById('stats').innerHTML = jsonresponse[0].name;
});
}, 1000);
function loadJSON(callback) {
var xobj = new XMLHttpRequest();
xobj.overrideMimeType('application/json');
xobj.open('GET', 'data.json', true);
xobj.onreadystatechange = function () {
if (xobj.readyState == 4 && xobj.status == '200') {
callback(xobj.responseText);
}
}
xobj.send(null);
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="/style.css">
</head>
<script src="./index.js"></script>
<script src="./node.js"></script>
<script src="./data.json"></script>
</body>
</html>
Can anyone advise on how to resolve this issue?