Cause Analysis and Solution for the window. location event not executed when the page is closed _ javascript skills

Source: Internet
Author: User
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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.