Cause analysis and solutions for window.location events not performed when the page is closed _javascript tips

Source: Internet
Author: User

1, the problem description:

JS defines widow.location = function (), the logout () function is not executed when the page closes.

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, the problem reason:

The Soapclient.invoke () method is called in logout (), and the argument is true, which means that the front-end and server communicate asynchronously, that is, the front-end has not received a response from the server side, and the following statement has been executed, which is performed as a front-end execution logout ( has not yet waited for the server's response, the page has been closed, so the performance of logout () has not been performed.

3, the solution:

Change the front-end and server communication mode to sync, and the problem is resolved by changing the Soapclient.invoke () method to False.

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.