Have doubts about the execution order of ajax

if (isPass = = true) {

    //
    $.ajax({
        type:"post",
        url :"/user/register",
        data:$("form").serialize(),
        dataType:"json",
        success:function(data){
            alert(data);
            if(data == "success"){
                alert("");
                window.location.href="/";//
            }else if(data == "fail"){
                alert(":"+data);
            }

        },
        error:function(){
            //window.location.href="/111";
            alert("");
            return false;
        }
    });
    alert("1");
    return true;
}

after executing the code, why does the registration exception 1 dialog box pop up first, and then the registration exception dialog box

Mar.11,2021

because ajax is asynchronous


ajax is Asynchronous Javascript And XML, that is, the requests it makes are asynchronous.
what is async? For example, if you turn on the washing machine to wash clothes, and then go to dinner, the washing machine will ring several times to remind you that you have finished washing, and at this time you go to collect your clothes, and the whole process is asynchronous.
if you have to wait for the laundry before going to dinner, the process is Synchronize.
so the callback function in ajax () parentheses in your code will only remind the code to come back and execute the corresponding method when the success and error events occur, and execute the code that follows ajax () when the success and error events do not occur.
Don't you know I made myself clear?


$.ajax({
    ....
    error:function(){
        //window.location.href="/111";
        alert("");
        return false;
    }
});
alert("1");
//$.ajax()alert("1"),error
....
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e4d9c8-4d2e4.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e4d9c8-4d2e4.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?