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

发布于 2024-11-08 15:07:47 字数 1477 浏览 0 评论 0原文

我通过jquery.ajax call()调用restAPI,一旦完成,我就无法使用其他ajax调用,因此我被spring security抛弃了。我注意到完成restAPI调用后JsessionID发生了变化(我使用httpFox插件来火狐)。因此,在其余 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);
                    }

                }    
    });

I am calling to a restAPI through jquery.ajax call() once it completed i cannot use my other ajax calls hence i am thrown away from the spring security. i noticed the JsessionID change upon complete the restAPI call (i used httpFox plugging for fire fox). so what ever i am doing after the rest API call i will redirect to the Login page by spring security. i noticed that i am not authorized user anymore. i thought if i can keep the initial 'jsessionID' and use it through my browser it will be fine. can anyone please give me some guidance how i can do it? Thanks in advance.

this is my code to the rest 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);
                    }

                }    
    });

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我要还你自由 2024-11-15 15:07:47

尝试附加 JSESSIONID=?在 jquery 中的其余 url 上

所以:

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

Try appending the JSESSIONID=? on the rest url in jquery

So:

url: restUrl="JSESSIONID=YOUR SESSION ID",
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文