1
class AjaxHelper {
constructor( service, requestType, bol ) {
this._uri = service;
this._requestType = requestType;
this._async = bol;
this._domain = 'https://private-4e803-salarycalculatorapi.apiary-mock.com';
this._url = this._domain + '' + this._uri;
let xhr = new XMLHttpRequest();
xhr.addEventListener("load", transferComplete, false);
xhr.open(this._requestType, this._url, this._async)
xhr.send();
function transferComplete(event) {
var data = JSON.parse(event.target.responseText);
return data;
}
console.log(data);
}
get url() {
return this._url;
}
}
I need to return the JSON parsing result of the XHR request to the Class scope, but I cannot understand how the functions passed on the request object work. VAR DATA ONLY EXISTS WITHIN ITS SCOPE.
<script src="app/helpers/AjaxHelper.js"></script>
<script>
var myresource = new AjaxHelper('/inss','GET', true);
myresource.data;
</script>