我需要重寫Ext.data.Connection才能顯示登錄表單。 我現在在Ext.application.launch中按預期工作。重寫Ext.data.Connection - 最佳實踐
是否有可能交換這段代碼在不同的地方像一個額外的文件?
我需要重寫Ext.data.Connection才能顯示登錄表單。 我現在在Ext.application.launch中按預期工作。重寫Ext.data.Connection - 最佳實踐
是否有可能交換這段代碼在不同的地方像一個額外的文件?
如果你只需要這個來識別用戶沒有通過身份驗證的時候,你可能想考慮做其他事情。比如增加一個處理程序的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);
}
然後,只需從你的application.launch()函數調用這個函數,並通過應用程序對象,以便範圍,如果定義。
爲什麼你想重寫連接以準確顯示登錄表單?如果他未通過身份驗證,向用戶顯示登錄表單? – sha 2012-03-13 10:32:20
正是。而且如果會話超時。 – 2012-03-13 10:34:20
我爲Ajax錯誤添加了全局處理程序,並在那裏分析了未驗證的錯誤。也許這也適合你。 – sha 2012-03-13 11:04:26