Home > Article > Web Front-end > Analysis and solutions to the reasons why the window.location event is not executed when closing the page_javascript skills
1. Problem description:
Define width.location = function() 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 of the problem:
The SOAPClient.invoke() method is called in logout(). The parameter is 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 and has already executed the following statements. In this question It appears that when the front end executes logout(), it has closed the page before waiting for the server's response, so it appears that logout() has not been executed.
3. Solution:
Change the communication method between the front end and the server to synchronization, that is, change true in the SOAPClient.invoke() method to false, and the problem is solved.