Javascript在模型提交后显示thankyou模态

时间:2017-08-17 11:13:11

标签: javascript bootstrap-modal

您好我有反馈表格的模型。模型提交后应显示另一个谢谢模型还需要存储本地存储。帮助我。

<div id="myModal2" class="modal fade" role="dialog">
<form action="" method="post" onSubmit="popUpToggle();" id="myModal2" >
<div class="form_fields feedbackfield">
<textarea id="txtMessage" name="txtMessage" rows="5" class="form-control contact-input" placeholder="Message *" required></textarea>
</div>
<div class="form_fields">
<input type="submit" class="contact-submit" name="SUBMIT" value="SUBMIT">
</div>
</form>
</div>

<div id="myModal4" class="modal fade" role="dialog">
      <div class="modal-dialog">                    
                <div class="popupHead3">
                   Thank you for your feedback    
                </div>    
      </div>

Javascript:

setTimeout(function() {
            if(localStorage.getItem("modalPopup")){$("#myModal2").modal('hide');}
            else{$('#myModal2').modal('show');}

        }, 5000);

        function popUpToggle(){         
            localStorage.setItem("modalPopup", "commit");
        }

2 个答案:

答案 0 :(得分:0)

您可以AJAX form尝试submit,然后使用

$('#myModal4').modal({show: 'true'});

答案 1 :(得分:0)

请尝试以下代码。

$("#myModal2").submit(function(){
  event.stopPropagation();
  event.preventDefault();
  $.ajax({
    type: "POST",
    url: /* submit url or form action url */,
    data: $(this).serialize(),
    success: function(d){
      /* do here what you want to do */

      $("#myModal4").modal({show: "true"});
    },
    dataType: "JSON"
  });
});