AJAX表单提交在IE11和Edge中不起作用

时间:2017-01-12 07:18:07

标签: jquery forms ajaxform ajaxsubmit malsup-ajax-form

无法解决表单提交问题。我将此代码用于我的表单:

        <div class="modal fade" id="modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
      <div class="modal-dialog" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <h4 class="modal-title" id="myModalLabel">Callback request</h4>
          </div>
          <div class="modal-body">
            <p>Please send us your contact information and we will call you back soon</p>
            <form class="callback" method="post" id="form1">
              <div class="input-group">
                <span class="input-group-addon"><span class="glyphicon glyphicon-user"></span></span>
                <input type="text" required class="form-control" id="firstName" name="fio" placeholder="Your name">
              </div>
              <br>
              <div class="input-group">
                <span class="input-group-addon"><span class="glyphicon glyphicon-earphone"></span></span>
                <input type="tel" required class="form-control" id="phoneNumber" name="phone" placeholder="Phone number">
              </div>
              <br>
              <div class="input-group">
                <span class="input-group-addon"><span class="glyphicon glyphicon-envelope"></span></span>
                <input type="email" class="form-control" id="inputEmail" name="email" placeholder="Email">
              </div>
              <br>
              <textarea class="form-control hidden-sm hidden-xs" rows="3" id="textField" name="comment" placeholder="Additional information" style="width:100%"></textarea>
              <input type="hidden" class="form-control" name="subject" value="Callback request">
            </form>
            <p class="text-center">We don't share any of your personal data with anyone</p>
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            <button type="submit" class="btn btn-primary submit" form="form1" onclick="yaCounter12657748.reachGoal('order'); return true;">Submit</button>
          </div>
        </div>
      </div>
    </div>

这个脚本

    <script type="text/javascript"> 
    $(document).ready(function()
    {
        var msg = $("#form1").serialize();
        var options = {
            type: "POST",
            url: "callback_form.php",
            data: msg,
            success: function(data) {
                $("#modal p").fadeOut("fast");
                $("#form1").fadeOut("fast", function(){
                    $(this).before("<h4 class='text-center'>Thank you for your message</h4>");
                    setTimeout("$('#modal').modal('hide')", 3000);
                });
            },
            error: function(xhr, str){
                alert("Error occured!");
            }
        };
        $('#form1').submit(function(e) {
            e.preventDefault();
            $('#form1').ajaxSubmit(options);
        });
    });
</script>

该表单在Mozilla,Opera,Chrome,Safari以及其他一些浏览器中运行良好,但在IE11和Edge中(我确定这不是整个列表)它在我做的时候什么都不做点击提交按钮。它不会褪色,也不会在控制台中显示任何错误。我还使用jQuery Form Plugin来解决Safari的问题,但不幸的是,由于某些原因它无法处理IE和Edge。也许这里有一些语法错误?

1 个答案:

答案 0 :(得分:0)

好的,我找到了为什么不在IE工作。您已在表单外插入按钮。把它放在里面。工作正常!

<div class="modal fade" id="modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">Callback request</h4>
      </div>
      <div class="modal-body">
        <p>Please send us your contact information and we will call you back soon</p>
        <form class="callback" method="post" id="form1">
          <div class="input-group">
            <span class="input-group-addon"><span class="glyphicon glyphicon-user"></span></span>
            <input type="text" required class="form-control" id="firstName" name="fio" placeholder="Your name">
          </div>
          <br>
          <div class="input-group">
            <span class="input-group-addon"><span class="glyphicon glyphicon-earphone"></span></span>
            <input type="tel" required class="form-control" id="phoneNumber" name="phone" placeholder="Phone number">
          </div>
          <br>
          <div class="input-group">
            <span class="input-group-addon"><span class="glyphicon glyphicon-envelope"></span></span>
            <input type="email" class="form-control" id="inputEmail" name="email" placeholder="Email">
          </div>
          <br>
          <textarea class="form-control hidden-sm hidden-xs" rows="3" id="textField" name="comment" placeholder="Additional information" style="width:100%"></textarea>
          <input type="hidden" class="form-control" name="subject" value="Callback request">
          <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            <button type="submit" class="btn btn-primary submit" form="form1" onclick="">Submit</button>
          </div>
        </form>
        <p class="text-center">We don't share any of your personal data with anyone</p>
      </div>

    </div>
  </div>
</div>