zoukankan      html  css  js  c++  java
  • 在jsp页面中设置了远程验证,在初始化时必须预先调用一次。

    参考链接:http://code.taobao.org/p/sztaotao/diff/5/trunk/code/src/main/webapp/webpage/modules/sys/roleForm.jsp

            在进行项目测试时,发现对设备管理模块进行“修改”时,没有任何反应(即没有“保存成功”的字样,控制台也不打印输出报错),后来在网上找资料,发现在进行“远程验证时,在初始化时必须预先调用一次”。因为当你打开修改对话框,不做任何更改直接submit,这时会触发远程效验,远程效验耗时较长,这时submit函数在等待远程效验结果然后在提交,而layer对话框不会阻塞(就是上面所说的没有任何反应),会直接关闭,同时会销毁表单,因此submit没有提交就被销毁了,导致提交表单失败。

    <script type="text/javascript">
    var validateForm;
    function doSubmit(){//回调函数,在编辑和保存动作时,供openDialog调用提交表单。
    if(validateForm.form()){
    $("#inputForm").submit();
    return true;
    }

    return false;
    }
    $(document).ready(function() {
    validateForm = $("#inputForm").validate({
    rules: {
               //设置了远程验证,在初始化时必须预先调用一次。            
    code: {remote: "${ctx}/equip/equipment/checkEquipmentCode?oldEquipmentCode=${equipment.code}"},
             messages: {
    code: {remote: "该设备编码已经存在!"},
    },
    submitHandler: function(form){
    loading('正在提交,请稍等...');
    form.submit();
    },
    errorContainer: "#messageBox",
    errorPlacement: function(error, element) {
    $("#messageBox").text("输入有误,请先更正。");
    if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
    error.appendTo(element.parent().parent());
    } else {
    error.insertAfter(element);
    }
    }
    });
    //在ready函数中预先调用一次远程校验函数,是一个无奈的回避案。(刘高峰)
    //否则打开修改对话框,不做任何更改直接submit,这时再触发远程校验,耗时较长,
    //submit函数在等待远程校验结果然后再提交,而layer对话框不会阻塞会直接关闭同时会销毁表单,因此submit没有提交就被销毁了导致提交表单失败。
    //inputForm 为提交表单的id
    $("#inputForm").validate().element($("#code"));
       });
    </script>
  • 相关阅读:
    Codeforces 845E Fire in the City 线段树
    Codeforces 542D Superhero's Job dp (看题解)
    Codeforces 797F Mice and Holes dp
    Codeforces 408D Parcels dp (看题解)
    Codeforces 464D World of Darkraft
    Codeforces 215E Periodical Numbers 容斥原理
    Codeforces 285E Positions in Permutations dp + 容斥原理
    Codeforces 875E Delivery Club dp
    Codeforces 888F Connecting Vertices 区间dp (看题解)
    Codeforces 946F Fibonacci String Subsequences dp (看题解)
  • 原文地址:https://www.cnblogs.com/kelly-one/p/8378445.html
Copyright © 2011-2022 走看看