From 2ffae59b9b4287f2af79da80c1d9dbfdce987db5 Mon Sep 17 00:00:00 2001
From: Val <35149642+vkservicesllc@users.noreply.github.com>
Date: Wed, 7 Nov 2018 15:24:58 -0500
Subject: [PATCH] Update jsonCap.js
---
ajax-requests/js/jsonCap.js | 40 +++++++++++++++++++------------------
1 file changed, 21 insertions(+), 19 deletions(-)
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 += '
| Company | ';
- content += 'First Name | Last Name | Title |
';
- for (i = 0; i < len; i++) {
- content += '| ' + respObj[i].Company + ' | ';
- content += '' + respObj[i]['First Name'] + ' | ';
- content += '' + respObj[i]['Last Name'] + ' | ';
- content += '' + respObj[i].Title + ' |
';
- if (i == len) content += '
';
+ 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 += '| Company | ';
+ content += 'First Name | Last Name | Title |
';
+ for (i = 0; i < len; i++) {
+ content += '| ' + respObj[i].Company + ' | ';
+ content += '' + respObj[i]['First Name'] + ' | ';
+ content += '' + respObj[i]['Last Name'] + ' | ';
+ content += '' + respObj[i].Title + ' |
';
+ if (i == len) content += '
';
+ }
+ 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);