diff --git a/ajax-requests/css/style.css b/ajax-requests/css/style.css new file mode 100644 index 0000000..fe3dbbf --- /dev/null +++ b/ajax-requests/css/style.css @@ -0,0 +1,18 @@ +* { + font-family: Arial; +} +body { + margin: 24px auto; + width: 920px; +} +button { + width: 280px; +} +table { + margin-top: 12px; + border-collapse: collapse; +} +th, td { + padding: 4px 9px; + border: 1px solid black; +} diff --git a/ajax-requests/files/jsonData.json b/ajax-requests/files/jsonData.json new file mode 100644 index 0000000..65fe1d2 --- /dev/null +++ b/ajax-requests/files/jsonData.json @@ -0,0 +1,32 @@ +[ + { + "Company": "CAROLINA LOGISTIC, INC", + "First Name": "Valentin", + "Last Name": "Khoroshkov", + "Title": "Driver Payroll" + }, + { + "Company": "CAROLINA LOGISTIC, INC", + "First Name": "Daniel", + "Last Name": "Pilyev", + "Title": "IT Manager" + }, + { + "Company": "CAROLINA LOGISTIC, INC", + "First Name": "Bob", + "Last Name": "Tumash", + "Title": "Dispatcher" + }, + { + "Company": "CAROLINA LOGISTIC, INC", + "First Name": "Kevin", + "Last Name": "Bondarenko", + "Title": "Insurance" + }, + { + "Company": "DELTA EXPRESS, INC", + "First Name": "Paul", + "Last Name": "Radchishin", + "Title": "Accounting" + } +] diff --git a/ajax-requests/files/xmlData.xml b/ajax-requests/files/xmlData.xml new file mode 100644 index 0000000..0ab315e --- /dev/null +++ b/ajax-requests/files/xmlData.xml @@ -0,0 +1,32 @@ + + + Truck Diesel + FUEL + true + + + Reefer Diesel + FUEL + true + + + Scale + MISC + true + + + Lumper + MISC + false + + + Parts + MAINTENANCE + true + + + Cash Fee + FEES + true + + diff --git a/ajax-requests/js/jsonCap.js b/ajax-requests/js/jsonCap.js new file mode 100644 index 0000000..84c687b --- /dev/null +++ b/ajax-requests/js/jsonCap.js @@ -0,0 +1,39 @@ +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'); + var rh = xhr.getAllResponseHeaders(); + console.log(rh); + } else { + console.log('Connection to Server succeeded. Content was not received due to error.'); + } + } else { + btnTxt = btnTxt.replace('hide', 'capture'); + } + div.innerHTML = content; + btn.textContent = btnTxt; + }; + xhr.open('GET', 'files/jsonData.json', true); + xhr.send(); +} diff --git a/ajax-requests/js/xmlCap.js b/ajax-requests/js/xmlCap.js new file mode 100644 index 0000000..8cd291f --- /dev/null +++ b/ajax-requests/js/xmlCap.js @@ -0,0 +1,38 @@ + +console.log('xmlCap.js has loaded...'); + +function captureXML() { + var xhr = new XMLHttpRequest(); + xhr.onload = function() { + var btn = document.getElementsByTagName('button')[1], + btnTxt = btn.textContent, + div = document.getElementById('capturedXML'), + content = '', + check = div.innerHTML == content; + if (check) { + if (xhr.status >= 200 && xhr.status < 400) { + var data = xhr.responseXML.getElementsByTagName('expense'); + content += ''; + content += ''; + for (var d = 0; d < data.length; d++) { + var checked = (data[d].getElementsByTagName('company')[0].textContent == 'true') ? ' checked' : ''; + content += ''; + content += ''; + content += ''; + } + content += '
COMPANY EXPENSE
CategoryGroupFile
for
Tax
' + data[d].getElementsByTagName('category')[0].textContent + '' + data[d].getElementsByTagName('group')[0].textContent + '
'; + btnTxt = btnTxt.replace('capture', 'hide'); + var rh = xhr.getAllResponseHeaders(); + console.log(rh); + } else { + console.log('Connection to Server succeeded. Content was not received due to error.'); + } + } else { + btnTxt = btnTxt.replace('hide', 'capture'); + } + div.innerHTML = content; + btn.textContent = btnTxt; + }; + xhr.open('GET', 'files/xmlData.xml', true); + xhr.send(); +} diff --git a/ajax-requests/page.html b/ajax-requests/page.html new file mode 100644 index 0000000..d2e84de --- /dev/null +++ b/ajax-requests/page.html @@ -0,0 +1,18 @@ + + + + Ajax + + + + + +

Test different document types

+ + + +
+ + + + diff --git a/test/test.html b/test/test.html new file mode 100644 index 0000000..2128acd --- /dev/null +++ b/test/test.html @@ -0,0 +1 @@ +Test

Test