Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

表单提交自动刷新? #41

Open
CarrotC opened this issue Dec 8, 2020 · 0 comments
Open

表单提交自动刷新? #41

CarrotC opened this issue Dec 8, 2020 · 0 comments

Comments

@CarrotC
Copy link

CarrotC commented Dec 8, 2020

callback函数中,没有validator的错误,函数会执行,但会把页面刷新。例如下面的代码,无法显示弹窗(modal1和modal2都不行),并且会把表单的内容重置,类似于页面刷新,请问如何解决这个问题,组织刷新?
`var validator = new Validator('form1',[
{
name:"temperature",
display:"请输入正确的体温值",
rules: 'is_money'
},{
name:"BMI",
display:"请输入正确的BML值",
rules: 'is_money'
}
],function(obj,evt){

var errors_elm = document.getElementById('error_msg');
errors_elm.style.display = 'none';
console.log(evt);
console.log(obj);
if(obj.errors.length>0){
// 判断是否错误
var error_str = '';
for (var i = 0; i < obj.errors.length; i++) {
error_str += i+1 + ':' + obj.errors[i].message + ';
';
}
errors_elm.style.display = "block";
errors_elm.innerHTML = error_str;

  $("#tipModal2").modal('show');

}else{
var CRE = $("input[name='CRE']").val();

var flag = true;
if($.trim(CRE) < 64 || $.trim(CRE) > 104){
  flag = false;
  $('#CRE_tip').show();
}

if(flag){
  $.ajax({
    type: "POST",   //提交的方法
    url: "/get_result/", //提交的地址
    data: $('#form1').serialize(),// 序列化表单值
    async: false,
    error: function (request) {  //失败的话
      //alert("Connection error");  
      $('#modal1').modal('show');
    },
    success: function (result) {  //成功
        console.log(result);  //就将返回的数据显示出来
        $('#modal2').modal('show');
      }
    });
  return false;
}else{
  // alert("hhh");
  $("#tipModal").modal('show');
}

}
});`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant