I wonder if I can get the responseText from an Ext.Ajax.Request call in a variable. I've tried many ways and "hacks" without success.
Example:
In this case, I am trying to assign the responseText to the accStatus variable and I am always getting undefined (I know this is NOT the right way) but I want to know exactly how to handle this (the correct way) and return it in my function without problems and in a "simple" way (if possible) like the below code.
By the way, I am using Ext 4.2.0.
Is there a way to do something like this?
Ext.define('Util.AccountManager', {
singleton: true,
getAccountStatus: function(id) {
var accStatus;
Ext.Ajax.request({
url : 'rest/accounts',
method : 'POST',
params : {id: id},
callback: function(o, s, r) {
accStatus = r.responseText;
}
});
return accStatus;
}
});
Ext.onReady(function () {
var id = '1234';
var accStatus = Util.AccountManager.getAccountStatus(id);
if(accStatus) {
console.log(accStatus);
}
});
If someone wants to help on this, you can use the following URLs for importing ExtJS:
I also made this jsfiddle just for "testing" (or at least trying because it is not possible to make ajax requests through this site).