$(document).ready(function() { $('#register-form').on('submit', function(e) { e.preventDefault(); if ($('#user_name').val() == '') { alert('Please enter the user!'); $("#user_name").focus(); return false; } if ($('#user_pwd').val() == '') { alert('Please input a password!'); $("#user_pwd").focus(); return false; } if ($('#user_pwd2').val() == '') { alert('Please input a password!'); $("#user_pwd2").focus(); return false; } if ($('#user_pwd').val() != $('#user_pwd2').val()) { alert('The passwords entered twice are inconsistent!'); $("#user_pwd2").focus(); return false; } if ($('#captchax').val() == '') { alert('Please enter the verification code!'); $("#captchax").focus(); return false; } var a = parseInt($("#a").val()); var b = parseInt($("#b").val()); var captchax = parseInt($("#captchax").val()); if(captchax != a+b){ alert("Verification code error"); return false; } if ($('#verify').val() == '') { alert('Please enter the verification code!'); $("#verify").focus(); return false; } $.ajax({ url: $(this).attr('action'), type: "post", //dataType: "json", data: $(this).serialize(), beforeSend: function () { $("#btn_submit").css("background","#fd6a6a").val("loading..."); }, success: function (res) { if(res.code==1){ location.href=res.url; } else { alert(res.msg); } }, complete: function () { $("#btn_submit").css("background","#fa4646").val("Register Now"); } }); }); });