dongwei5740 2018-09-06 10:33
浏览 234

使用mPDF生成PDF时显示加载图像

I have a form to submit name of exam and mark range to generate a PDF with name of student, mark and rank. The form values for posted to another script which is used to generate a PDF using mPDF. Since there are many records it is taking sometime to generate PDF.

The form calling the script is as below:

<form class="form-horizontal form-validation" role="form" method="POST" action="generatePDF.php">
       <input type="text" name="examid" required />
       <input type="text" name="markmin" requried />
       <input type="text" name="markmax" required />
       <input type="submit" name="submit" value="Submit" />
</form>

I want to know if I can display a loading image while the script is running, called from the POST.

  • 写回答

1条回答 默认 最新

  • dsm13698679318 2018-09-06 11:44
    关注

    There are two options: replace the submit button with a generic spinner (e.g. font awsome) or, full page modal with a spinner. Both of these options will require javascript listeners on the form submit.

    Replace Submit Button

    (function($) {
      $('form').on('submit', function(e) {
        e.preventDefault(); //remove this line. Only included for demo purposes.
        $(this).find('[name="submit"]').replaceWith('<i class="fa fa-spinner fa-spin"></i>');
      });
    })(jQuery)
    <link href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" rel="stylesheet" />
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <form class="form-horizontal form-validation" role="form" method="POST" action="generatePDF.php">
      <input type="text" name="examid" required />
      <input type="text" name="markmin" requried />
      <input type="text" name="markmax" required />
      <input type="submit" name="submit" value="Submit" />
    </form>

    Modal Popup

    (function($) {
      $('form').on('submit', function(e) {
        e.preventDefault(); //remove this line. Only included for demo purposes.
      });
    })(jQuery)
    .modal.show .modal-dialog.modal-dialog {
      width: 25vw;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      margin: 0;
    }
    
    .modal .modal-content {
      width: 25vw;
      font-size: 25vw;
      background: transparent;
      border: none;
      color: red;
    }
    <link href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" rel="stylesheet" />
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
    <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet" />
    
    <form class="form-horizontal form-validation" role="form" method="POST" action="generatePDF.php">
      <input type="text" name="examid" required />
      <input type="text" name="markmin" requried />
      <input type="text" name="markmax" required />
      <input type="submit" name="submit" value="Submit" data-toggle="modal" data-target="#exampleModal" />
    </form>
    
    <!-- Modal -->
    <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
      <div class="modal-dialog" role="document">
        <div class="modal-content">
          <div class="modal-body">
            <i class="fa fa-spinner fa-spin"></i>
          </div>
        </div>
      </div>
    </div>

    In both these cases, remove the e.preventDefault() line as this will stop the form from actually submitting.

    The beauty of the modal option is you can replace the spinner (font awesome again) with any image you want.

    </div>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大