function addUser() {
let data={}
$.each($("-sharpaddUser").serializeArray(),function () {
data[this.name]=this.value;
})
let userName=$("input[name="userName"]").val();
let password=$("input[name="password"]").val();
let password2=$("input[name="password2"]").val();
let mobile=$("input[name="mobile"]").val();
let remarks=$("input[name="remarks"]").val();
let mobileReg=/^1[3|4|5|8][0-9]\d{4,8}$/i;
if(userName.length==0){
let formAlert=$("input[name="userName"]").next(".form-alert");
formAlert.show();
formAlert.html("");
}
if(password.length==0){
let formAlert=$("input[name="password"]").next(".form-alert");
formAlert.show();
formAlert.html("");
}
if(password2.length==0){
let formAlert=$("input[name="password2"]").next(".form-alert");
formAlert.show();
formAlert.html("");
}else if(password2!==password){
let formAlert=$("input[name="password2"]").next(".form-alert");
formAlert.show();
formAlert.html("");
}
if(remarks.length==0){
let formAlert=$("input[name="remarks"]").next(".form-alert");
formAlert.show();
formAlert.html("");
}
if(mobile.length==0){
let formAlert=$("input[name="mobile"]").next(".form-alert");
formAlert.show();
formAlert.html("");
}else if(!mobileReg.test(mobile)){
let formAlert=$("input[name="mobile"]").next(".form-alert");
formAlert.show();
formAlert.html("");
}
$.ajax({
type : "POST",
url : "/api/user/add",
data :data,
success : function(result) {
$(".alert").show();
if(result.msg==""){
$(".alert").addClass("alert-success").removeClass("alert-danger");
}
$(".alert").text(result.msg);
setTimeout(function () {
$(".alert").hide();
},3000)
console.log(result)
},
error:function (result) {
$(".alert").show();
$(".alert").text(result.msg);
setTimeout(function () {
$(".alert").hide();
},3000)
}
});
}
as in the above code, I wrote the form verification. How to ensure that after the verification is correct, then jump to ajax, and then jump directly to ajax