Update jsonCap.js

This commit is contained in:
Val
2018-11-07 15:24:58 -05:00
committed by GitHub
parent ea636656a1
commit 2ffae59b9b

View File

@@ -3,26 +3,28 @@ console.log('jsonCap.js is running...');
function captureJSON() { function captureJSON() {
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
xhr.onload = function() { xhr.onload = function() {
if (xhr.status >= 200 && xhr.status < 400) { var div = document.getElementById('capturedJSON'),
var div = document.getElementById('capturedJSON'), content = '',
content = '', check = div.innerHTML = content;
respObj = JSON.parse(xhr.responseText), if (check) {
len = respObj.length, if (xhr.status >= 200 && xhr.status < 400) {
i; var respObj = JSON.parse(xhr.responseText),
console.log(xhr.responseText); len = respObj.length,
content += '<table><tr><th>Company</th>'; i;
content += '<th>First Name</th><th>Last Name</th><th>Title</th></tr>'; console.log(xhr.responseText);
for (i = 0; i < len; i++) { content += '<table><tr><th>Company</th>';
content += '<tr><td>' + respObj[i].Company + '</td>'; content += '<th>First Name</th><th>Last Name</th><th>Title</th></tr>';
content += '<td>' + respObj[i]['First Name'] + '</td>'; for (i = 0; i < len; i++) {
content += '<td>' + respObj[i]['Last Name'] + '</td>'; content += '<tr><td>' + respObj[i].Company + '</td>';
content += '<td>' + respObj[i].Title + '</td></tr>'; content += '<td>' + respObj[i]['First Name'] + '</td>';
if (i == len) content += '</table>'; content += '<td>' + respObj[i]['Last Name'] + '</td>';
content += '<td>' + respObj[i].Title + '</td></tr>';
if (i == len) content += '</table>';
}
div.innerHTML = content;
} else {
console.log('Connection to Server succeeded. Content was not received due to error.');
} }
if (div.innerHTML != '') content = '';
div.innerHTML = content;
} else {
console.log('Connection to Server succeeded. Content was not received due to error.');
} }
}; };
xhr.open('GET', 'files/jsonData.json', true); xhr.open('GET', 'files/jsonData.json', true);