function turndown(){
art.dialog.open("regist/toturndown",{
width: 400,height: 320,
title: "驳回申请",
lock: true,
drag: false,
ok: function (iframeWin, topWin) {
var paramObj = new Object();
paramObj.source_code = source_code;
paramObj.verify_status = "03";
paramObj.reject_reason = reject_reason;
$.ajax({
type : 'post',
url : 'regist/savecheck',
data : paramObj,
dataType : 'json',
cache : false,
success : function(result) {
if (JSON.parse(result).success== true) {
alertBox({content: "驳回申请成功", width: 320, height: 120, lock: true, drag: false, ok: function(){
location.href="<%=basePath%>regist/verifycheck";
}});
} else {
alertBox({content: "驳回申请失败", width: 320, height: 120, lock: true, drag: false, ok: true});
}
},
error:function(){
alertBox({content: "请求服务器失败", width: 320, height: 120, lock: true, drag: false, ok: true});
}
}) --%>
},
cancel: true
});
}
}
以上是我的代码,
错误现象:当调用方法的turndown(),dialog弹出框的页面没有加载出来,直接跳转登录页面(因为后台校验了session是否为空,判断超时),而当dialog.open调用到后台的时候session已经超时了(不是很懂,还没执行到ajax提交就产生session超时,而事实证明确实是$.ajax引起的。)
解决办法:先是按照我的怀疑去定位代码,即使没有弹出框,直接使用ajax请求就会出现session超时,所以我判断和ajax有关,然后我百度查询换成ajax的原生写法,代码如下
art.dialog.open("regist/toturndown",{
width: 400,
height: 320,
title: "驳回申请",
lock: true,
drag: false,
ok: function (iframeWin, topWin) {
//获取驳回原因
var reject_reason = iframeWin.document.getElementById('reject_reason').value;
if(reject_reason==null || reject_reason==""){
alertBox({content: "请填写驳回原因", width: 320, height: 120, lock: true, drag: false, ok: true});
return false;
}
var req = createXMLHTTPRequest();
if(req){
req.open("POST", "regist/savecheck", true);
req.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=gbk;");
req.send("source_code="+source_code+"&verify_status=03&reject_reason="+reject_reason);
req.onreadystatechange = function(){
if(req.readyState == 4){
if(req.status == 200){
var result=req.responseText;
data=eval(result);
if (JSON.parse(data).success== true) {
alertBox({content: "驳回申请成功", width: 320, height: 120, lock: true, drag: false, ok: function(){
location.href="<%=basePath%>regist/verifycheck";
}});
} else {
alertBox({content: "驳回申请失败", width: 320, height: 120, lock: true, drag: false, ok: true});
}
}else{
alertBox({content: "请求服务器失败", width: 320, height: 120, lock: true, drag: false, ok: true});
}
}
}
}
<%--
var paramObj = new Object();
paramObj.source_code = source_code;
paramObj.verify_status = "03";
paramObj.reject_reason = reject_reason;
$.ajax({
type : 'post',
url : 'regist/savecheck',
data : paramObj,
dataType : 'json',
cache : false,
success : function(result) {
if (JSON.parse(result).success== true) {
alertBox({content: "驳回申请成功", width: 320, height: 120, lock: true, drag: false, ok: function(){
location.href="<%=basePath%>regist/verifycheck";
}});
} else {
alertBox({content: "驳回申请失败", width: 320, height: 120, lock: true, drag: false, ok: true});
}
},
error:function(){
alertBox({content: "请求服务器失败", width: 320, height: 120, lock: true, drag: false, ok: true});
}
}) --%>
},
cancel: true
});
}
然后就不会出现session超时,特别提示req.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=gbk;"); (我尝试注解掉,但是报错,所以这这句话是重点。)