gpt4 book ai didi

javascript - 覆盖 Ext.data.Connection - 最佳实践

转载 作者:数据小太阳 更新时间:2023-10-29 06:12:58 25 4
gpt4 key购买 nike

我需要覆盖 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);
}

然后只需从您的 application.launch() 函数调用此函数并传递应用程序对象,以便定义作用域。

关于javascript - 覆盖 Ext.data.Connection - 最佳实践,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9682249/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com