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

Analysis and solutions to the reasons why the window.location event is not executed when closing the page_javascript skills

WBOY
Release: 2016-05-16 16:38:22
Original
1092 people have browsed it

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);
  }

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 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.

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!