console.log('jsonCap.js has loaded...'); function captureJSON() { var xhr = new XMLHttpRequest(); xhr.onload = function() { var btn = document.getElementsByTagName('button')[0], btnTxt = btn.textContent, div = document.getElementById('capturedJSON'), content = '', check = div.innerHTML == content; if (check) { if (xhr.status >= 200 && xhr.status < 400) { var respObj = JSON.parse(xhr.responseText), len = respObj.length, i; content += ''; content += ''; for (i = 0; i < len; i++) { content += ''; content += ''; content += ''; content += ''; if (i == len) content += '
CompanyFirst NameLast NameTitle
' + respObj[i].Company + '' + respObj[i]['First Name'] + '' + respObj[i]['Last Name'] + '' + respObj[i].Title + '
'; } btnTxt = btnTxt.replace('capture', 'hide'); } else { console.log('Connection to Server succeeded. Content was not received due to error.'); } } div.innerHTML = content; btn.textContent = btnTxt; }; xhr.open('GET', 'files/jsonData.json', true); xhr.send(); }