我正在使用ExtJS,我想从后端读取userRights并将其存储在JS对象中。
所以我有这个:
var userRights = {};
Ext.Ajax.request({
url: myUrl,
success: function(response, opts) {
var obj = Ext.decode(response.responseText);
store.loadData(obj.rights);
console.log(obj.rights[0])
if (obj.rights) {
console.log("The Block")
userRights = obj.rights;
} else {
Ext.MessageBox.show({
title: _I('Fehler'),
msg: "Something is wrong",
icon: Ext.MessageBox.INFO,
buttons: Ext.Msg.OK,
closable: true,
fn: function() {}
});
}
},
failure: function(response, opts) {
console.log('server-side failure with status code ' + response.status);
}
});
console.log(userRights);
在控制台中,它输出以下内容:
{}
{IsAdmin: 1, IsAuthorized: 1}
The Block
由于运行顺序错误,因此userRights
对象为空。我在这里做什么错了?