Bootstrap模式在表单提交和页面刷新后保持打开

rdrgkggo  于 2023-06-27  发布在  Bootstrap
关注(0)|答案(1)|浏览(143)

我有一个引导模式的形式,我用发送一个4字段的消息。提交按钮按下后,我想向用户显示一个“谢谢”的消息。但我的表单却没有关闭,页面正在刷新。
我怎样才能让模态表单保持打开状态,以便在提交按钮下方显示消息。
谢谢你!

<section class="modal-form">
  <!-- Modal Video first page -->
  <div class="modal fade" id="participa-modal" tabindex="-1" role="dialog" aria-labelledby="participa-modal">
    <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">Participă la un demo!</h4>
        </div>
        <div class="modal-body">
          <div class="form-group">
            <form id="form" method="post" class="contact" action="" enctype="multipart/form-data" data-parsley-validate>
                <div class="row">
                  <div class="col-md-6">
                    <div class="form-group">
                      <input type="text" name="homepage_firstname" id="homepage_firstname" class="form-control-contact" placeholder="Nume" required>
                    </div>
                    <div class="form-group">
                      <input type="email" name="homepage_email" id="homepage_email" class="form-control-contact" placeholder="Email" required>
                    </div>
                    <div class="form-group">
                      <input type="text" name="homepage_phone" id="homepage_phone" class="form-control-contact" placeholder="Telefon" data-parsley-type="number" minlength="10" maxlength="10" required>
                      <input type="hidden" name="inner_message" id="inner_message" value="Participare demo curs!">
                    </div>
                  </div>
                  <div class="col-md-6">
                    <div class="form-group">
                      <textarea class="form-control-contact" name="homepage_message" id="homepage_message" placeholder="Scrisoare de intentie"></textarea>
                    </div>
                  </div>
                </div>
                <div class="form-actions">
                    <input type="hidden" name="homepagesubmitted" value="TRUE" />
                    <button type="submit" class="btn orange sign-in-btn">Înscrie-te</button>
                </div>
                <?php echo $homepage_send ?>
              </form>
          </div>
        </div>
      </div>
    </div>
  </div>
  <!-- End Modal Video first page -->
  </section>

更新:好的。所以我已经设法使它工作以下代码:

$(function () {
    var frm = $('#participa-modal');
    frm.submit(function (ev) {
        $.ajax({
            type: frm.attr('method'),
            url: frm.attr('action'),
            data: frm.serialize(),
            success: function (data) {
            alert('ok');
            location.reload();
            }
        });
    ev.preventDefault();
    });
});

问题是我如何替换**alert('ok')**以在发送按钮下的同一弹出窗口中指向感谢。

fafcakar

fafcakar1#

$(".modal-body form").submit(function(e) {
    var url = "ActionScript.php"; // the script where you handle the form input.
    $.ajax({
           type: "POST",
           url: url,
           data: $(this).serialize(), // serializes the form's elements.
           success: function(data) {
               $(this).html("Thank you!!!");
           }
         });
    e.preventDefault(); // avoid to execute the actual submit of the form.
});

检查以上代码是否符合您的要求

使用的术语

$(".modal-body form")类和子窗体选择器,以便针对您提交的form
.submit(在表单的submit上触发事件
type: "POST"用于通过post方法安全地遍历数据
.serialize()用于收集(组装)并发送过帐数据
success:是一个回调,以便在提交成功时继续。

相关问题