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 pairing result of the XHR request to the scope of the Class, but I can not understand how the functions passed in the request object work. VAR DATA ONLY EXIST WITHIN YOUR SCOPE.
<script src="app/helpers/AjaxHelper.js"></script>
<script>
var myresource = new AjaxHelper('/inss','GET', true);
myresource.data;
</script>