ajax提交 session失效

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;");     (我尝试注解掉,但是报错,所以这这句话是重点。)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值