Here is a code snippet featuring an object with a function that makes an AJAX call. The function currently returns an empty array, but we need to figure out how to return the data after receiving the response.
var receivedData = [];
var AjaxUtil = {
fetchData: function (requestedResource) {
request
.get(endpointUrl + requestedResource)
.set('Accept', 'application/json')
.end(function (error, response) {
if(!error) {
receivedData = response.body;
} else {
console.log('Error occurred.');
}
});
return receivedData;
}