我需要重写 Ext.data.Connection 来显示登录表单。目前我在 Ext.application.launch 中实现了这个功能,效果如预期。
请问是否可以将这段代码放到其他地方,比如一个额外的文件中?
我需要重写 Ext.data.Connection 来显示登录表单。目前我在 Ext.application.launch 中实现了这个功能,效果如预期。
请问是否可以将这段代码放到其他地方,比如一个额外的文件中?
如果您只需要识别用户未经身份验证的情况,您可能希望考虑其他方法。比如向Ajax单例添加一个处理程序:
function addAjaxErrorHandler(object) {
Ext.Ajax.on('requestexception', function(conn, response, options, e) {
var statusCode = response.status,
errorText = null,
captionText = response.statusText;
// 404 - file or method not found - special case
if (statusCode == 404) {
Ext.MessageBox.alert('Error 404', 'URL ' + response.request.options.url + ' not found');
return;
}
if (response.responseText != undefined) {
var r = Ext.decode(response.responseText, true);
if (r != null) {
// 401 - not authenticated. For some reason we don't have authentication cookie anymore
if (r.ErrorCode == 401) {
Ext.MessageBox.alert('Error', 'You must log in to use application',
function() {
// do something when user is not authenticated
object);
return;
}
errorText = r.ErrorMessage;
}
if (errorText == null)
errorText = response.responseText;
}
if (!captionText)
captionText = 'Error ' + statusCode;
Ext.MessageBox.alert(captionText, errorText);
},
object);
}