重要的一步就是 async:false, 因为ajax默认是异步的,即 默认为async:true 。设为false后就可以把ajax中返回到前台的pass值在函数CheckForm中使用。

function CheckForm(){ var pass; var msg; var url="${ctx}/crm/contact.action?method:checkForm"; var qq=document.getElementById("contact_QQ").value; var mobile=document.getElementById("contact_mobile").value; var email=document.getElementById("contact_email").value; $.ajax({ url : url, async:false, type : "post", dataType : "json", data : { QQ:qq, mobile:mobile, email:email }, success : function(data) { pass=data.pass; msg=data.msg; if(pass){ alert("保存成功!"); }else{ alert(msg); } } }); if(pass) return true; else return false; } <button type="submit" class="btn btn-sm btn-primary savaBtn" name="method:save" onclick="return CheckForm()">保存</button>

 

相关文章:

  • 2021-04-10
  • 2022-12-23
  • 2021-11-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-31
猜你喜欢
  • 2021-10-19
  • 2022-12-23
  • 2021-11-04
  • 2022-01-25
  • 2022-12-23
  • 2021-09-17
  • 2022-12-23
相关资源
相似解决方案