Analysis of the reasons why the window.location event was not executed when the page was closed and the solution

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

1. Problem description:

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

window.onunload = function() {

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: