var getJSON = function(url, callback) { var xhr = new XMLHttpRequest(); xhr.open('GET', url, true); xhr.responseType = 'json'; xhr.onload = function() { var status = xhr.status; if (status === 200) { callback(null, xhr.response); } else { callback(status, xhr.response); } }; xhr.send(); }; var postJSON = function(url, data, callback) { var xhr = new XMLHttpRequest(); xhr.open('POST', url, true); xhr.responseType = 'json'; xhr.setRequestHeader('Content-Type', 'application/json'); xhr.onload = function() { var status = xhr.status; if (status === 200) { callback(null, xhr.response); } else { callback(status, xhr.response); } }; xhr.send(data); }; function loadSites(){ getJSON('http://localhost:8000/api/Sites', function(err, data) { data = Object.values(data); if (err !== null) { alert('Something went wrong: ' + err); } else { $(".rendered").remove(); data.forEach (function(site) { renderSite(site); }) } } ); } function renderSite(site){ siteString = `
${site.description}