涛哥实力派,是一匹千里马,可惜了水货上司。
失败发生在彻底的放弃之后。我对我的上司失望极了。
公司最近在完成一个项目,项目已经进行到尾声了,还没有进行对回话为空进行过滤。在涛哥提出后,上司研究了半天解决不了,最后丢给涛哥解决。虽说解决问题是每个人的义务,不是每个人的责任。但涛哥还是抱着学习的态度,解决问题。最终得以解决。直接上重新的代码:
Ext.override(Ext.Ajax, {
request: function(options) {
options = options || {};
if(options.url&&options.url.indexOf('login.jsp')>-1){
location.href='http://download.csdn.net/detail/xmt1139057136/7113051';
return;
}
var me = this,
scope = options.scope || window,
username = options.username || me.username,
password = options.password || me.password || '',
async,
requestOptions,
request,
headers,
xhr;
if (me.fireEvent('beforerequest', me, options) !== false) {
requestOptions = me.setOptions(options, scope);
if (me.isFormUpload(options)) {
me.upload(options.form, requestOptions.url, requestOptions.data, options);
return null;
}
if (options.autoAbort || me.autoAbort) {
me.abort();
}
async = options.async !== false ? (options.async || me.async) : false;
xhr = me.openRequest(options, requestOptions, async, username, password);
headers = me.setupHeaders(xhr, options, requestOptions.data, requestOptions.params);
request = {
id: ++Ext.data.Connection.requestId,
xhr: xhr,
headers: headers,
options: options,
async: async,
timeout: setTimeout(function() {
request.timedout = true;
me.abort(request);
}, options.timeout || me.timeout)
};
me.requests[request.id] = request;
me.latestId = request.id;
if (async) {
xhr.onreadystatechange = Ext.Function.bind(me.onStateChange, me, [request]);
}
xhr.send(requestOptions.data);
if (!async) {
return me.onComplete(request);
}
return request;
} else {
Ext.callback(options.callback, options.scope, [options, undefined, undefined]);
return null;
}
}
});
这里判断如果你的ajax请求访问的是login.jsp页面就跳转到csdn页面上。
这里在贴上在所有的ajax请求前,都加上beforerequest事件。
Ext.Ajax.addListener("beforerequest", function(conn, options, eOpts ){
if(options){
if(options.url&&options.url.indexOf('UserReport-getDeviceReport')>-1){
location.href='http://download.csdn.net/detail/xmt1139057136/7112943';
return;
}
}
}, this);
好方法有很多,我这里使用的是requestcomplete事件,后台使用过滤器,如果发现回话为空null,我就修改response的
response.setContentType("text/html;charset=UTF-8;ifLogin=ERROR");
然后在返回的结果里判断,存在content-type存在ifLogin=ERROR,就跳转到后台的登录页面。
Ext.Ajax.addListener("requestcomplete",function(conn, response, options, eOpts){
var msg = response.getAllResponseHeaders();
if(msg['content-type'].indexOf('ifLogin=ERROR') != -1){
window.location.href=serverPath+'admin/login.jsp';
}
},this);
好了,到这里就结束了。欢迎大家关注我的个人博客。
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有