Before the Fetch API, we had to utilize the XMLHttpRequest system. To create a request for server data, we had to write something like the following:
const oldReq = new XMLHttpRequest();
oldReq.addEventListener('load', function(ev) {
document.querySelector('#content').innerHTML =
JSON.stringify(ev.target.response);
});
oldReq.open('GET', 'http://localhost:8081/sample');
oldReq.setRequestHeader('Accept', 'application/json');
oldReq.responseType = 'json';
oldReq.send();
First, you will notice that the object type is called XMLHttpRequest. The reason is due to who invented it and the reason behind it. Microsoft had originally developed the technique for the Outlook web access product. Originally, they were transferring XML documents back and forth, and so they named the object for...