AngularJS - 进度条为 100% 后重新加载页面 5 秒

     2023-05-09     7

关键词:

【中文标题】AngularJS - 进度条为 100% 后重新加载页面 5 秒【英文标题】:AngularJS - Reload page 5 seconds once progress bar is 100% 【发布时间】:2019-10-18 01:38:26 【问题描述】:

我想在进度条达到 100% 后 5 秒后重新加载页面

我的代码是:

<!DOCTYPE HTML>
<!--
/*
 * jQuery File Upload Plugin AngularJS Demo
 * https://github.com/blueimp/jQuery-File-Upload
 *
 * Copyright 2013, Sebastian Tschan
 * https://blueimp.net
 *
 * Licensed under the MIT license:
 * https://opensource.org/licenses/MIT
 */
-->

<html lang="en">
<head>
<!-- Force latest IE rendering engine or ChromeFrame if installed -->
<!--[if IE]>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<![endif]-->
<meta charset="utf-8">
<title>jQuery File Upload Demo - AngularJS version</title>
<meta name="description" content="File Upload widget with multiple file selection, drag&amp;drop support, progress bars, validation and preview images, audio and video for AngularJS. Supports cross-domain, chunked and resumable file uploads and client-side image resizing. Works with any server-side platform (PHP, Python, Ruby on Rails, Java, Node.js, Go etc.) that supports standard HTML form file uploads.">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Bootstrap styles -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- Generic page styles -->
<link rel="stylesheet" href="css/style.css">
<!-- blueimp Gallery styles -->
<link rel="stylesheet" href="https://blueimp.github.io/Gallery/css/blueimp-gallery.min.css">
<!-- CSS to style the file input field as button and adjust the Bootstrap progress bars -->
<link rel="stylesheet" href="css/jquery.fileupload.css">
<link rel="stylesheet" href="css/jquery.fileupload-ui.css">
<!-- CSS adjustments for browsers with JavaScript disabled -->
<noscript><link rel="stylesheet" href="css/jquery.fileupload-noscript.css"></noscript>
<noscript><link rel="stylesheet" href="css/jquery.fileupload-ui-noscript.css"></noscript>
<style>
/* Hide Angular JS elements before initializing */
.ng-cloak 
    display: none;

</style>
</head>
<body>
<div class="container">
    <!-- The file upload form used as target for the file upload widget -->
    <form id="fileupload" action="server/php/" method="POST" enctype="multipart/form-data" data-ng-app="demo" data-ng-controller="DemoFileUploadController" data-file-upload="options" data-ng-class="'fileupload-processing': processing() || loadingFiles">
<input type="hidden" name="wo" value="1111_">     
     <!-- Redirect browsers with JavaScript disabled to the origin page -->
        <noscript><input type="hidden" name="redirect" value="error.asp"></noscript>
        <!-- The fileupload-buttonbar contains buttons to add/delete files and start/cancel the upload -->
        <div class="row fileupload-buttonbar">
            <div class="col-lg-7">
                <!-- The fileinput-button span is used to style the file input field as button -->
                <span class="btn btn-success fileinput-button" ng-class="disabled: disabled">
                    <i class="glyphicon glyphicon-plus"></i>
                    <span>Add files...</span>
                    <input type="file" name="files[]" multiple ng-disabled="disabled">
                </span>
                <button type="button" class="btn btn-primary start" data-ng-click="submit()">
                    <i class="glyphicon glyphicon-upload"></i>
                    <span>Start upload</span>
                </button>
                <button type="button" class="btn btn-warning cancel" data-ng-click="cancel()">
                    <i class="glyphicon glyphicon-ban-circle"></i>
                    <span>Cancel upload</span>
                </button>
                <!-- The global file processing state -->
                <span class="fileupload-process"></span>
            </div>
            <!-- The global progress state -->
            <div class="col-lg-5 fade" data-ng-class="in: active()">
                <!-- The global progress bar -->
                <div class="progress progress-striped active" data-file-upload-progress="progress()"><div class="progress-bar progress-bar-success" data-ng-style="width: num + '%'"></div></div>
                <!-- The extended global progress state -->
                <div class="progress-extended">&nbsp;</div>
            </div>
        </div>
        <!-- The table listing the files available for upload/download -->
        <table class="table table-striped files ng-cloak">
            <tr data-ng-repeat="file in queue" data-ng-class="'processing': file.$processing()">
                <td data-ng-switch data-on="!!file.thumbnailUrl">
                    <div class="preview" data-ng-switch-when="true">
                        <a data-ng-href="file.url" title="file.name" download="file.name" data-gallery><img data-ng-src="file.thumbnailUrl" ></a>
                    </div>
                    <div class="preview" data-ng-switch-default data-file-upload-preview="file"></div>
                </td>
                <td>
                    <p class="name" data-ng-switch data-on="!!file.url">
                        <span data-ng-switch-when="true" data-ng-switch data-on="!!file.thumbnailUrl">
                            <a data-ng-switch-when="true" data-ng-href="file.url" title="file.name" download="file.name" data-gallery>file.name</a>
                            <a data-ng-switch-default data-ng-href="file.url" title="file.name" download="file.name">file.name</a>
                        </span>
                        <span data-ng-switch-default>file.name</span>
                    </p>
                    <strong data-ng-show="file.error" class="error text-danger">file.error</strong>
                </td>
                <td>
                    <p class="size">file.size | formatFileSize</p>
                    <div class="progress progress-striped active fade" data-ng-class="pending: 'in'[file.$state()]" data-file-upload-progress="file.$progress()"><div class="progress-bar progress-bar-success" data-ng-style="width: num + '%'"></div></div>
                </td>
                <td>
                    <button type="button" class="btn btn-primary start" data-ng-click="file.$submit()" data-ng-hide="!file.$submit || options.autoUpload" data-ng-disabled="file.$state() == 'pending' || file.$state() == 'rejected'">
                        <i class="glyphicon glyphicon-upload"></i>
                        <span>Start</span>
                    </button>
                    <button type="button" class="btn btn-warning cancel" data-ng-click="file.$cancel()" data-ng-hide="!file.$cancel">
                        <i class="glyphicon glyphicon-ban-circle"></i>
                        <span>Cancel</span>
                    </button>
                    <button data-ng-controller="FileDestroyController" type="button" class="btn btn-danger destroy" data-ng-click="file.$destroy()" data-ng-hide="!file.$destroy">
                        <i class="glyphicon glyphicon-trash"></i>
                        <span>Delete</span>
                    </button>
                </td>
            </tr>
        </table>
    </form>
    <br>
</div>
<!-- The blueimp Gallery widget -->
<div id="blueimp-gallery" class="blueimp-gallery blueimp-gallery-controls" data-filter=":even">
    <div class="slides"></div>
    <h3 class="title"></h3>
    <a class="prev">‹</a>
    <a class="next">›</a>
    <a class="close">×</a>
    <a class="play-pause"></a>
    <ol class="indicator"></ol>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js" integrity="sha384-xBuQ/xzmlsLoJpyjoggmTEz8OWUFM0/RC5BsqQBDX2v5cMvDHcMakNTNrHIW2I5f" crossorigin="anonymous"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js" integrity="sha384-r6jjWwxAypHaESwS5an5J9dkfzwQuKVNV9FZM9B6fnt8PFuY0cVwLhV7BltCZhLy" crossorigin="anonymous"></script>
<!-- The jQuery UI widget factory, can be omitted if jQuery UI is already included -->
<script src="js/vendor/jquery.ui.widget.js"></script>
<!-- The Load Image plugin is included for the preview images and image resizing functionality -->
<script src="https://blueimp.github.io/JavaScript-Load-Image/js/load-image.all.min.js"></script>
<!-- The Canvas to Blob plugin is included for image resizing functionality -->
<script src="https://blueimp.github.io/JavaScript-Canvas-to-Blob/js/canvas-to-blob.min.js"></script>
<!-- Bootstrap JS is not required, but included for the responsive demo navigation -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<!-- blueimp Gallery script -->
<script src="https://blueimp.github.io/Gallery/js/jquery.blueimp-gallery.min.js"></script>
<!-- The Iframe Transport is required for browsers without support for XHR file uploads -->
<script src="js/jquery.iframe-transport.js"></script>
<!-- The basic File Upload plugin -->
<script src="js/jquery.fileupload.js"></script>
<!-- The File Upload processing plugin -->
<script src="js/jquery.fileupload-process.js"></script>
<!-- The File Upload image preview & resize plugin -->
<script src="js/jquery.fileupload-image.js"></script>
<!-- The File Upload audio preview plugin -->
<script src="js/jquery.fileupload-audio.js"></script>
<!-- The File Upload video preview plugin -->
<script src="js/jquery.fileupload-video.js"></script>
<!-- The File Upload validation plugin -->
<script src="js/jquery.fileupload-validate.js"></script>
<!-- The File Upload Angular JS module -->
<script src="js/jquery.fileupload-angular.js"></script>
<!-- The main application script -->
<script src="js/app.js"></script>
</body>
</html>

我希望整个页面重新加载一次,或者在上传完成后重定向到另一个 URL 或向用户发送警报消息。

再次感谢您对此提供的任何帮助...

更新:

我尝试编辑文件 jquery.fileupload.js 并添加了以下代码,但它不起作用或出错..

        // Callback for successful uploads:
         done: function (e, data) 
              alert("Upload Done");
window.location.href = "http://www.GOOD.com";
         , // .bind('fileuploaddone', func);

        // Callback for failed (abort or error) uploads:
         fail: function (e, data) 
             alert("Upload FAILED");
window.location.href = "http://www.FAILED.com";
         , // .bind('fileuploadfail', func);

【问题讨论】:

请编辑您的帖子,包括minimal, reproducible example 并限制您的问题,使其具体明确。 @compcobalt 我的回答有帮助吗?你需要更多细节吗?我添加了一个你问的例子 【参考方案1】:

基本上,您需要强制重新加载。如果您将相同的位置传递给window.location.href,它实际上不会导航。

我添加了一个最小的工作示例,其中还有一个文本会在 2 秒后更改,因此我们可以看到在 sn-p 中发生重新加载时文本会变回。

    运行代码sn-p 等待文本更改(2 秒) 尝试上传文件 上传应该失败,因为 URL 不应该在 *** 上工作 您会看到警报,然后文本将恢复为原始文本,表示页面重新加载

$(document).ready(() => 
  // not needed! only here for the demo
  setTimeout(() => $('#text').text('text changed after 2 seconds').addClass('changed'), 2000);

  $('#fileupload').fileupload(
    url: 'http://localhost:3000',
    dataType: 'json',
    done: function(e, data) 
      alert('success!');
      location.reload();
    ,
    fail: function(e, data) 
      alert('failure!');
      location.reload();
    ,
    progressall: function(e, data)  /* ... */ 
  );
);
#text 
  padding: 0.5em;


.changed 
  color: red;
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script src="https://rawgit.com/blueimp/jQuery-File-Upload/master/js/vendor/jquery.ui.widget.js"></script>
<script src="https://rawgit.com/blueimp/jQuery-File-Upload/master/js/jquery.iframe-transport.js"></script>
<script src="https://rawgit.com/blueimp/jQuery-File-Upload/master/js/jquery.fileupload.js"></script>


<!-- This will help us see the reload happening -->
<div id="text">page initial load!</div>
<input id="fileupload" type="file" name="files[]" multiple>

如果您想确保从服务器而不是浏览器的缓存重新加载,请将true 作为location.reload 的第一个参数传递:

location.reload(true);

等待 5 秒再重新加载

您可以使用setTimeout 来做到这一点。用以下 sn-p 替换 location.reload()

setTimeout(() => location.reload(), 5000);

【讨论】:

嗨,我尝试添加,但没有任何反应.. 没有错误或任何东西。很抱歉,如果你给我一个演示可以吗?我想我做错了什么。感谢您的帮助。 @compcobalt 提供了一个有效的 sn-p。让我知道这是否更清楚。【参考方案2】:

window.location.href 更改为相同的页面/url 将不起作用。 看这里:Difference between window.location.href=window.location.href and window.location.reload()

对于延迟,请使用 setTimeout()

如果您确定“完成”功能确实有效,请更改为

done: function (e, data) 
    alert("Upload Done");

    var delayInMilliseconds = 5000; //5 seconds
    setTimeout(function() 
        location.reload(); //use 'location.reload(true);' if you want to force reload from server
    , delayInMilliseconds);
,

最好的问候,

婆罗门

【讨论】:

PyQt 启动后进度跃升至 100%

】PyQt启动后进度跃升至100%【英文标题】:PyQtprogressjumpsto100%afteritstarts【发布时间】:2018-04-0409:18:28【问题描述】:当我在doWork方法中运行代码时,通过单击button1,进度条按预期工作。但是,当我将列表从其他方法(即btn2、btn3... 查看详情

我想在 30 秒后重新启动一个圆形进度条

】我想在30秒后重新启动一个圆形进度条【英文标题】:Iwanttorestartacircularprogressbarafter30seconds【发布时间】:2022-01-0223:07:20【问题描述】:constuseProgress=(maxTimeInSeconds=30)=>const[elapsedTime,setElapsedTime]=useState(0);const[progress,setProgres 查看详情

AngularJS - 删除Hashbang后页面重新加载时出现404错误[重复]

】AngularJS-删除Hashbang后页面重新加载时出现404错误[重复]【英文标题】:AngularJS-404erroronpagereloadafterHashbangremoval[duplicate]【发布时间】:2019-01-2211:26:05【问题描述】:使用从我的路由中删除hashbang后$locationProvider.html5Mode(true);现在当... 查看详情

如何在AngularJS中通过AJAX加载数据后重新初始化数据表?

】如何在AngularJS中通过AJAX加载数据后重新初始化数据表?【英文标题】:HowdoIre-initializedatatablesAFTERdatahasloadedviaAJAXinAngularJS?【发布时间】:2015-10-1111:16:57【问题描述】:我正在使用AngularJS和Datatables以及服务器端脚本通过AJAX获取... 查看详情

uploadifive.js怎么去掉进度条

参考技术AUploadify中上传完毕会默认保留进度条并显示100%,前提设置removeCompleted为false,而UploadiFive中上传完毕后进度条自动消失 参考技术BUploadify中上传完毕会默认保留进度条并显示100%,前提设置removeCompleted为false,而UploadiFive... 查看详情

AngularJS:AngularJS 渲染模板后如何运行附加代码?

】AngularJS:AngularJS渲染模板后如何运行附加代码?【英文标题】:AngularJS:HowtorunadditionalcodeafterAngularJShasrenderedatemplate?【发布时间】:2012-08-3112:31:32【问题描述】:我在DOM中有一个Angular模板。当我的控制器从服务中获取新数据时... 查看详情

*(已更新)关于visualstudio2019安装时vsinstaller无法下载文件,进度条为0,显示网络有问题的解决办法(代码片段)

VisualStudio2019中的安装问题详细解决方法前言一、下载地址二、问题解决1、连接WIFI2、修改DNS刷新本地DNS解析缓存(分割线,7-13更新)前言因为最近要学习C++和C#,所以在寻找了很多编程软件... 查看详情

迭代完成后如何删除 tqdm 中的进度条

】迭代完成后如何删除tqdm中的进度条【英文标题】:Howtoremoveprogressbarintqdmoncetheiterationiscomplete【发布时间】:2020-09-1419:21:29【问题描述】:我该如何存档?fromtqdmimporttqdmforlinkintqdm(links):try:#DoSomeStffexcept:passprint("Done:")结果:100%|... 查看详情

如何重新加载圆形进度条

】如何重新加载圆形进度条【英文标题】:howtoreloadacircularprogressbar【发布时间】:2015-12-0921:59:58【问题描述】:我对画布以及如何创建圆形进度条进行了一些网络搜索,我得到了这个。我对在网上找到的代码片段进行了一些更... 查看详情

循环进度显示超过100%

】循环进度显示超过100%【英文标题】:Circularprogressshowmorethan100%【发布时间】:2020-03-2420:09:08【问题描述】:我在这篇文章中做了一个圆形图表:https://medium.com/@pppped/how-to-code-a-responsive-circular-percentage-chart-with-svg-and-css-3632f8cd7705... 查看详情

图片上传的简单进度“栏” - 立即达到 100% [重复]

】图片上传的简单进度“栏”-立即达到100%[重复]【英文标题】:simpleprogress\'bar\'forimageupload--immediatelyat100%[duplicate]【发布时间】:2015-10-2314:03:58【问题描述】:我正在尝试在我的PHP图像上传中添加一个简单的进度条/数字。如果... 查看详情

进度条,最大值并重置为 100%

】进度条,最大值并重置为100%【英文标题】:Progressbar,maxandreseton100%【发布时间】:2017-11-2813:47:47【问题描述】:我正在处理连接到sql中的XP和MAXXP的进度条。每次单击按钮时,您都会获得1xp,最大xp为10。我希望当用户达到100%XP... 查看详情

华为od机试2023最新字符串重新排列字符串重新排序(c++100%)

...行如下处理后输出:1、单词内部调整:对每个单词字母重新按字典序排序2、单词间顺序调整:1)统计每个单词出现的次数,并按次数降序排列2)次数相同,按单词长度升序排列3)次数和单词长度均相同,按字典升序排列请输... 查看详情

office安装进度0

...装期间可能发生的Internet连接问题。 参考技术BOffice安装进度为0,有可能是你的网络不好,一直显示是0,网络不好导致进度被限制。也可能是因为某种原因下载受到的限制,我们重新点击,重新下载就可以了。 查看详情

重新渲染视图而不重新加载/刷新 AngularJS 应用程序

】重新渲染视图而不重新加载/刷新AngularJS应用程序【英文标题】:Re-renderingtheviewwithoutreloading/refreshingtheAngularJSApplication【发布时间】:2019-04-0510:04:09【问题描述】:我现在正在处理的应用程序包含大量ng-include指令,我讨厌重新... 查看详情

Swift Progress View 动画使进度条超过 100%

】SwiftProgressView动画使进度条超过100%【英文标题】:SwiftProgressViewanimationmakesthebargofurtherthan100%【发布时间】:2017-06-0618:52:18【问题描述】:当为ProgressView使用动画时,如果我让动画用完,它完全可以正常工作,但如果我在动画仍... 查看详情

angularjs进度条动态宽度

】angularjs进度条动态宽度【英文标题】:angularjsprogressbardynamicwidth【发布时间】:2016-03-1111:35:24【问题描述】:我有一个图片库,其中包含一张照片、一个竖起大拇指按钮和每个项目的进度条。所有项目都仅源自一个JSON对象。我... 查看详情

js控制进度条到达100%跳转界面一

进度条一般在手机上用到的比较广泛,刚好最近的项目也是一直在做手机站,这个特效是手机端的一个界面,现在我把改成pc端了,进度条的快慢速度和样式可自行调节,改动也是很方便的,不多说,看代码:<!DOCTYPEhtml><h... 查看详情