【问题标题】:form submitting multiple times in IE depends on no.of click of submit button在 IE 中多次提交表单取决于提交按钮的点击次数
【发布时间】:2017-09-18 21:18:09
【问题描述】:

我正面临 IE 的问题,表单被提交了很多次,w.r.t 提交按钮的点击次数.. 这是我的流程..

  -> User enters the data in the form and upon click of submit button, will validate 
       the from
  -> if form data is valid, will open a bootstrap confirm request modal to show the data that was 
        entered and will provide another confirm submit button..when users clicks on 
        Confirm Submit button, will submit the form

到目前为止一切正常,但是当我们关闭确认请求引导模式并再次单击提交,然后现在单击模式上的确认提交按钮时,表单被提交了两次..

所以基本上当我们关闭确认请求模式并一次又一次地重做相同的提交过程(意味着关闭确认请求模式并单击初始化提交按钮),然后最后当我们点击模式上的确认提交按钮时,然后根据提交按钮的点击次数,表单被提交了很多次......

** its happening only in IE**

我的初始化提交按钮代码:

<div class="form-group actionBtnGrp">
        <div class="col-sm-offset-5 col-sm-7">
            <button type="reset" class="btn btn-form-action btn-primary-grey resetFormData">
                <spring:message code="cancel"></spring:message>
            </button>
            <button type="submit" class="btn btn-form-action btn-primary-sub formSubmitBtn" id="saveBtn">
                <spring:message code="submit"></spring:message>
            </button>
        </div>
</div>

我的确认模式 - 确认提交按钮

<div class="modal-footer">
        <button type="button" id="subForm"class="btn btn-primary-sub">Confirm
            Request</button>
        <button type="button" class="btn btn-secondary"
            data-dismiss="modal">Cancel</button>
    </div>

我的 jquery 提交代码:

$("#policy-form").on('submit', function(event){
    var isvalidate=$('#policy-form').valid(); //calling validation method and doing validation
    if(isvalidate) {
        if(!$("#confirm-request").data('bs.modal') || $("#confirm-request").data('bs.modal').isShown != true) {  //checking confirm modal is open and opening
            $("#confirm-submit").modal('show');
            $('#subForm').text('Confirm Request')
              .prop('disabled', false);
            event.preventDefault ? event.preventDefault() : (event.returnValue = false);
        }
    }   
});

确认请求模式打开并做某事,最后将有确认提交按钮来提交请求..

$('#confirm-request').on('show.bs.modal', function (e) { // confirm request bootstrap modal
 ..//// doing something else 
   // finally submitting the request upon clicking confirm submit from 

$('#subForm').click(function () {
        $(this).text('Submitting ...')
          .prop('disabled', true);
        $('#policy-form').submit();  // submitting the form..
   });

如前所述,在一次又一次地关闭和重新打开引导模式时,将多次提交表单。(当我们点击确认提交按钮时......IE缓存提交按钮的点击次数然后提交这么多次..?)

非常感谢任何帮助,因为从昨天开始就对此感到震惊..

谢谢..

【问题讨论】:

    标签: javascript jquery html forms jsp


    【解决方案1】:

    这看起来不像是 IE 问题。这是您的 click 绑定的问题。您将click 处理程序绑定到on 的回调内的元素。这意味着您每次显示模态时都会绑定一个新的处理程序。

    $('#confirm-request').on('show.bs.modal', function (e) { // confirm request bootstrap modal
    ..//// doing something else 
    // finally submitting the request upon clicking confirm submit from 
    
    $('#subForm').click(function () {
        $(this).text('Submitting ...')
          .prop('disabled', true);
        $('#policy-form').submit();  // submitting the form..
    });
    

    让它看起来像这样

    $('#subForm').click(function () {
        $(this).text('Submitting ...')
          .prop('disabled', true);
        $('#policy-form').submit();  // submitting the form..
    });
    
    $('#confirm-request').on('show.bs.modal', function (e) { // confirm request bootstrap modal
    ..//// doing something else 
    // finally submitting the request upon clicking confirm submit from 
    

    【讨论】:

    • 感谢@gforce301 的回复...我不是 jquery/javascript 的专业人士..你能帮我在这种情况下我需要做什么..!!
    • 但我需要显示确认请求模式,在查看数据后,他将单击模式上的确认提交按钮,然后提交来自..
    • 我已经把它放在答案中了。把$('#subForm').click开头的部分去掉,放到$('#confirm-request').on开头的部分上面
    • 如果您希望我帮助您完成所有这些,您需要将更多代码放在您的问题中可以阅读的地方。我只能“想象”这么多。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-02
    • 2012-07-26
    • 2021-08-02
    • 2021-08-27
    • 2018-11-13
    相关资源
    最近更新 更多