Recently, when I was working on a project, I encountered a problem: window when the page is closed. if the location event is not executed, you may not be able to understand the specific cause. The problem description is as follows:
Widow. location = function () defined in JS. When the page is closed, the logout () function is not executed.
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. cause:
Call SOAPClient in logout. invoke () method. The parameter is true, indicating that the frontend and server communicate asynchronously. That is, the frontend has executed the following statement before receiving the response from the server, in this case, when the front-end executes logout (), the page is closed before the server responds. Therefore, logout () is not executed.
3. solution:
Change the communication mode between the frontend and the server to synchronization, and change "true" to "false" in the SOAPClient. invoke () method to solve the problem.