Ajax Async for Deeper understanding

Source: Internet
Author: User

The past impression of the Ajax asynchronous operation, has been incredibly in the $.ajax function inside the asynchronous, is really wrong, the actual asynchronous operation, is for the entire JS file.

Today I finally realized that the actual situation was as follows:

$ (function () {
    //"box cue layer" Initialize
    $.like.initalertmsgdiv ();
    Determine if the account creates a wallet
    isexistwallet ();
    Wallet Information Display
    showwalletinfo ();
    Load Recent Transactions
    Pageclick (1, 3);
    
First determine whether the account created a wallet, not created, in time to create an empty wallet. The next step is to load the information in the wallet.

There is a wallet non-null validation in the Load Wallet information function. At first, the Ajax operation in the Isexistwallet () function was asynchronous, resulting in the absence of the wallet and the creation of the purse, which was performed to report the wallet as an empty error.

So at this point Ajax should be changed to synchronous operation, to determine whether the account created wallet code as follows:

function Isexistwallet () {
    //ajax query
    $.ajax ({
        URL: $.like.getrooturl () + "/wallet/isexistwallet.htm",
        type: "POST",
        data: {
            "type": Type
        },
        DataType: "JSON",
        Async:false,
        success:function (data) {
            var res = data.res;
            var msg = data.msg;
            if (res==2) {//Login timeout
                $.like.alert_msg (MSG, 1, $.like.getrooturl () + '/agent/home.html ');
            } else if (res!=0) {
                $.like.alert_msg (Msg, 0, ');}
            }
    );
}
Async:false can get it done.

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.