Home  >  Article  >  Web Front-end  >  Reasons and solutions for closing page window.location event not executing_javascript skills

Reasons and solutions for closing page window.location event not executing_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:38:001619browse

1. Problem description:

Widow.location = function() is 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 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 in an asynchronous manner. 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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn