I created a class in ExtJs including variables and function that modifies internal properties to the class.
My problem is focused when I want to change internal properties of the class (from internal or externals functions of class).
The class:
var Ws = new Ext.Class({
WsUrl: '',
WsErrorCode: 0,
WsOut: null,
CoreVersion: '',
AppName: '',
AppVersion: '',
BrowserLanguage: GetBrowserLanguage(),
BrowserUserAgent: GetBrowserLanguage(),
BrowserToken: '',
constructor: function(url) {
this.WsUrl = url;
return this;
},
SendCmd: function(CmdName) {
var WsOut;
var WsErrorCode;
//Send request
Ext.Ajax.request({
loadMask: true,
url: this.WsUrl,
params: {cmd: CmdName},
success: function(response, opts) {
WsOut = Ext.decode(response.responseText);
WsErrorCode = response.status;
},
failure: function(response, opts) {
WsOut = Ext.decode(response.responseText);
WsErrorCode = response.status;
}
});
this.WsOut = WsOut;
this.WsErrorCode = WsErrorCode;
return this;
}
});
Here the object is created:
var WsTest = new Ws('ws.php');
WsTest = WsTest.SendCmd('GetBrowserToken');
alert(WsTest.WsErrorCode); //Here, the code must return 200 but the value is 0 ... why ?
Do you have an idea of why This.WsOut = WsOut does not set the property correctly ?
your issue is that the request is asyncronous. So by the time you assign wsOut, the request is still in progress.
Add the scope to the request and set the internal attribute on the callback functions.