My JavaScript code includes a request function, but I believe it's outdated and I'd like to convert it into an AJAX call. Can someone assist with this update?
Here is the current function in my JavaScript file:
function loadRest() {
const request = new XMLHttpRequest();
request.onreadystatechange = function () {
if (this.readyState === 4) {
let result = parseResponse(this.status, this.responseText);
if (result != null) {
Rest.rests = result;
createTable();
}
}
};
request.open("GET", Rest.baseURL + "/byCompany/" + logginedCompanyId, true);
request.send();
}
function parseResponse(status, responseText) {
console.log(responseText);
let responseObject = JSON.parse(responseText);
if (status !== 200 || (responseObject.error && responseObject.error != null)) {
alert("Error: " + responseObject.error);
return null;
}
return responseObject.result;
}