function loadJSON(path, success, error) { var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function() { if (xhr.readyState === XMLHttpRequest.DONE) { if (xhr.status === 200) { success(JSON.parse(xhr.responseText)); } else { error(xhr); } } }; xhr.open("GET", path, true); xhr.send(); } loadJSON('/cgi-bin/quiz4/quiz4.json', function(data) { document.getElementById("count").textContent = data.count; }, function(xhr) { console.error(xhr); } );