After the login is successful, request the backend interface and return no login to discover that the session id has changed.

I initially asked for the login interface. After the login was successful, I asked for the data interface and returned not logged in.
so I separate the login API from the data interface and put it in a separate html file, and then test and find that the, session id is consistent if the request is successful.
then the data interface in the project can also request successfully, but once the login period expires, the data interface in the project returns not logged in again.
as long as I refresh the separate html (including login interface and data interface), the data interface in the project can be requested successfully

background is java

I have looked up a lot of information on the Internet, which is basically different from my situation. After
, I also tried to delay the data interface with setTimeout because of asynchronism, but it was not successful.

$.ajax({
    url:"http://server/admin/login",
    type:"post",
    data:{username:"xxx",pw:"xxx"},
    xhrFields: {
        withCredentials: true
    },
    crossDomain: true,
    success:function(res){
        console.log(res)
        //
    }
})
setTimeout(function(){
    $.ajax({
        url:"http://server/admin/getData",
        type:"post",
        data:{id:"10031",coin:"$",amunt:"1000"},
        xhrFields: {
            withCredentials: true
        },
        crossDomain: true,
        success:function(res){
            console.log(res)
            //
            //sessionidsessionid
        }
    })
},2000)

I don"t know why the request can be successful after taking out the login interface and the data interface separately, but the unlogged, session id change is returned in the project?

Apr.11,2021

because you have crossed domains, your session_id has changed, because you can't read cookie. There are two solutions:
1. The background interface adopts jwt authentication
2. The backend setting allows you to read the following things across domains

on the backend.

header('Access-Control-Allow-Origin:');
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept,X_Requested_With, x-xsrf-token");
header('Access-Control-Allow-Methods: GET, POST, PUT, OPTIONS');
header('Access-Control-Allow-Credentials: true');

$.Ajax increase

beforeSend: function(xhr) {
    xhr.withCredentials = true;
}
Menu