Why the close page window.location event was not executed and how to resolve it

  • 2020-03-30 03:47:20
  • OfStack

1. Problem description:

JS defines widow. Location = function(), and the logout() function is not executed when the page is closed.


window.onunload = function() {
logout();
}

function logout(reqParam, callback){
var userManageServiceUrl = "http://" + getServerAddr() + "/axis2/services/UserManageService";
var urlList = [];
var url = window.location.href;
urlList = url.split("?");
var sessionID = urlList[1];
reqParam.sessionID = sessionID;
var pl = new SOAPClientParameters();
var reqParamStr = JSON.stringify(reqParam);
pl.add("reqParam", reqParamStr);
SOAPClient.invoke(userManageServiceUrl, "logout", pl, false, callback);
}

2. Reasons for the problem:

The soapclient.invoke () method is called in logout(), with the parameter of true, which means that the front end and the server communicate asynchronously. That is, the front end has not received the response from the server side, and then the following statement has been executed.

3. Solutions:

The problem is resolved by synchronizing the communication between the front end and the server and changing the soapclient.invoke () method from true to false.


Related articles: