diff --git a/ajax-requests/js/jsonCap.js b/ajax-requests/js/jsonCap.js index 708dd4d..9d72780 100644 --- a/ajax-requests/js/jsonCap.js +++ b/ajax-requests/js/jsonCap.js @@ -3,26 +3,28 @@ console.log('jsonCap.js is running...'); function captureJSON() { var xhr = new XMLHttpRequest(); xhr.onload = function() { - if (xhr.status >= 200 && xhr.status < 400) { - var div = document.getElementById('capturedJSON'), - content = '', - respObj = JSON.parse(xhr.responseText), - len = respObj.length, - i; - console.log(xhr.responseText); - 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 + '
'; + var 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; + console.log(xhr.responseText); + 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 + '
'; + } + 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);