$ Submission return false ( "") submit the form;. Effect

$("#registerForm").submit(function () {
if(checkUserName() && checkPassword()){
$.post("user/regist", $(this).serialize(), function (info) {
    alert(1111);
    if (info.flag) {
        location.href = "register_ok.html";
    } else {
        $("#error_msg").html(info.errorMsg);
    }
});
}
return false;});

The above is a form submission, a method of binding events is asynchronous ajax submit, but if you do not write the final return false, what happens?

I wrote a form form action = "login.html", when you click Submit, pop-up 1111, it is executed ajax request, but click confirmation page and jump directly to the login page, and are not execution of judgment behind the statement. Why is that?

ajax default is asynchronous, so when you trigger ajax action, the main thread is not going to ignore the callback ajax content directly execute the next statement, you determine whether or not the return value is not legal to block the main thread in callback submission form action.
So return false in fact is used to prevent a form submission actions, that is, I closed the submission of the main thread.

Guess you like

Origin blog.csdn.net/xiao_Ray/article/details/81902002