Home > Web Front-end > JS Tutorial > body text

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

WBOY
Release: 2016-05-16 16:38:00
Original
1627 people have browsed it

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);
}
Copy after login

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.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template