Dealing with Javascript scopes has always been a struggle for me.
My goal is to display a loading dialog while waiting for a JSON response, as shown below:
toQueueRequest.onreadystatechange = function () {
if (toQueueRequest.readyState === 4 && toQueueRequest.status === 200) {
this.$.processingDialog.close();
this.$.confirmDialog.open();
} else if (toQueueRequest.readyState === 4){
this.$.processingDialog.close();
this.$.errorMsg="An error has occurred!"
this.$.errorDialog.open();
}
};
//var data = JSON.stringify({"RestoCode": window.location.pathname, "Fingerprint": this.finger});
if (this.sector == "Any") {this.sector = null;};
var data = JSON.stringify({"RestoCode": restoCode, "Fingerprint": finger, "PhoneNumber": this.cellno, "PersonalName": this.name, "QuantityPeople": this.pas, "SectorId": this.sector});
toQueueRequest.send(data);
this.$.reviewDialog.close();
this.$.processingDialog.open();
However, when inside the onreadystatechange function, this.$.ProcessingDialog is not defined.
How can I access it from within?
Thank you very much!