Within my Webapp (which is currently running at localhost/myApp/
), I am utilizing an ajax call as shown below:
$.ajax({
type: "GET",
url: "http://localhost:8080/my.module/Login/login?user=abc&password=123",
xhrFields: {
withCredentials: true,
},
success: onResult,
error: onError,
});
This ajax call is used for logging in to the server. The response from the server includes a boolean value indicating the success of the login, along with the following header:
Set-Cookie: JSESSIONID=167C57FA1E3529433938E744F7C4AC52; Path=/my.module
By setting the xhrField option "withCredentials: true", the browser automatically manages the cookie and adds the Cookie header to all subsequent requests:
Cookie: JSESSIONID=167C57FA1E3529433938E744F7C4AC52
Although this method works smoothly, a new issue has arisen where the server fails to clear a session when using the logout interface, thereby preventing sessions from being closed (and unfortunately, I do not have access to the server). To properly log out, it's necessary to remove the session cookie on the client side so that a new one can be retrieved from the server. However, I am unable to locate or delete the cookie since the document.cookie
variable appears empty within my web application. Attempts to read the document.cookie
variable from localhost/myApp/my.module/
and localhost/my.module/
also return empty results. Additionally, trying to overwrite the cookie using
document.cookie = "JSESSIONID=ABC; Path=/my.module";
does not update the server requests with the modified cookie information. Is there a way to successfully remove the cookie?
While I acknowledge that this approach may seem like a workaround, it aligns with what I'm seeking as the server developers are unable to rectify the bug promptly and have requested me to implement a client-side solution.