ajax调用另一个url重置JsessionId因此无法继续其他链接

时间:2011-05-19 15:20:13

标签: javascript jquery spring-mvc spring-security

我通过jquery.ajax call()调用restAPI一旦完成,我就无法使用其他的ajax调用,因此我被抛弃spring security。我注意到完成restAPI调用后JsessionID更改(我使用httpFox插入fire fox)。所以我在其余的API调用之后正在做什么,我将通过spring security重定向到登录页面。我注意到我不再是授权用户了。我想如果我能保留最初的'jsessionID'并通过我的浏览器使用它就可以了。任何人都可以给我一些指导我怎么做?提前致谢。

这是我对其余api的代码

        jQuery.ajax({
        type: "POST",
        //contentType: "application/json; charset=utf-8",
        url: restUrl,
        data: "{}",
        dataType: "json",
        success: function(msg) {
                // load grids
                try{
                    loadBaseGrid(); //this is a jqgrid
                    //will trigger once ajax call is success. but this 
                    //will not complete successfully. becouse of the jsession ID change
                }catch(e){
                    trace('Error in loadBaseGrid -'+e);
                }
            },
        beforeSend : function(req) {
                //req.setRequestHeader("Access-Control-Allow-Origin", "*");
                //req.setRequestHeader('Authorization', token);
                },
        error:function (xhr, ajaxOptions, thrownError){

                    var res = xhr.responseText;
                    try{
                        //var err = JSON.parseWithDate(res);
                        trace(err);
                    }catch(e){
                        trace('Error ->'+e);
                    }

                }    
    });

1 个答案:

答案 0 :(得分:0)

尝试附加JSESSIONID =?在jquery的其余网址

所以:

url: restUrl="JSESSIONID=YOUR SESSION ID",