douxuzui4590 2015-09-04 10:20
浏览 51

使用JQuery在执行PHP脚本时动画进度条

I got a form that sends some information on a PHP page. I managed to animate the progress bar on form submit and I would like to animate the progress bar on the script execution duration too.

My script gets the information and sends them to a lot of email addresses (like newsletters).

My FORM with the progress bar:

<form class="form-horizontal fadeIn animated" id="formImport" action="PHP/traitementImport.php" method="POST" enctype="multipart/form-data">
    <div class="form-group">
        <label class="col-sm-2 control-label">Catégorie</label>
        <div class="col-sm-10">
            <?php
                $sql2 = "SELECT idg, intitule, titrefr, titreuk FROM groupe;";
                $req2 = mysqli_query($mysqli, $sql2) or die('Erreur SQL !<br/>' . $sql2 . '<br/>' . mysqli_error($mysqli));
            ?>
            <select class="form-control" name="categ" style="height:34px;" id="listeGroup">
                <?php
                    while ($data2 = mysqli_fetch_array($req2)) { // Remplissage du SELECT
                        $idg = $data2['idg'];
                        $intitule = $data2['intitule'];
                        $titrefr = $data2['titrefr'];
                        $titreuk = $data2['titreuk'];                    
                ?>

                        <option value="<?php echo $idg ?>" class="valGroup"><?php echo $intitule ?></option>
                        <option value="<?php echo $titrefr ?>" id="<?php echo $idg ?>titrefr" style="display:none;"></option>
                        <option value="<?php echo $titreuk ?>" id="<?php echo $idg ?>titreuk" style="display:none;"></option>
                <?php } ?>
            </select>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">Titre FR</label>
        <div class="col-sm-10">
            <input type="text" id="inputRapportFR" name="rapportFR" class="form-control" placeholder="Titre du rapport français">
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">Titre UK</label>
        <div class="col-sm-10">
            <input type="text" id="inputRapportUK" name="rapportUK" class="form-control" placeholder="Titre du rapport anglais">
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">Rapport FR</label>
        <div class="col-sm-10">
            <div class="input-group">
                <span class="input-group-btn">
                    <span class="btn btn-primary btn-file">
                        Choisir dossier <input id="rapportFR" name="rapportFR[]" type="file" multiple directory="" webkitdirectory="" mozdirectory="">
                    </span>
                </span>
            <input type="text" class="form-control file" placeholder="RAPPORT FRANCAIS" readonly />
        </div>
      </div>
  </div>
  <div class="form-group">
      <label class="col-sm-2 control-label">Rapport UK</label>
      <div class="col-sm-10">
          <div class="input-group">
              <span class="input-group-btn">
                  <span class="btn btn-primary btn-file">
                      Choisir dossier <input id="rapportUK" name="rapportUK[]" type="file" multiple directory="" webkitdirectory="" mozdirectory="">
                  </span>
              </span>
              <input type="text" class="form-control file" placeholder="RAPPORT ANGLAIS" readonly>
          </div>
      </div>
  </div>
  <div class="form-group">
      <div class="col-sm-offset-2 col-sm-10">
          <button id="btnEnvoyer" type="submit" class="btn btn-default">Envoyer</button>
      </div>
  </div>
</form>
<div class="progress" style="display:none;">
    <div class="bar"></div>
        <div class="percent">0%</div>
    </div>
<div id="status"></div>

My Javascript Code:

(function () {
        var bar = $('.bar');
        var percent = $('.percent');
        var status = $('#status');

        $('form').ajaxForm({
            beforeSend: function () {
                $(".progress").show();
                status.empty();
                var percentVal = '0%';
                bar.width(percentVal)
                percent.html(percentVal);
            },
            uploadProgress: function (event, position, total, percentComplete) {
                var percentVal = percentComplete + '%';
                bar.width(percentVal)
                percent.html(percentVal);
            },
            complete: function (xhr) {
                bar.width("100%");
                percent.html("100%");
                status.html(xhr.responseText);
            }
        });
    })();

I want to call 'MyScript.php', execute it without changing page and display and animate my progress bar on execution of it.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度