你好,我想實現一些我在http://elfga.com/得到的代碼。我想將它與AspUpload的文件上傳腳本集成在一起。我分開工作,但不在一起。當文件上傳時,如何運行jquery函數來更新進度條?
如果我換了jQuery在
$(document).ready(function(){
...
});
jQuery的運行,民調報告上傳狀態,並如預期寫入控制檯的腳本。如果我把它綁定到表單提交使用
$(document).ready(function(){
$("#addForm").submit(function() {
...
});
});
的文件上傳,但jQuery的不輪詢腳本和數據寫入到控制檯。
我對jquery相當陌生。我在這裏弄錯了什麼?由於
HTML
<form name="addForm" id="addForm" method="post" enctype="multipart/form-data" action="moduleMaterialUpd.asp?PID=368337C0351A5DE6" onSubmit="getProgress()">
<fieldset>
<div>
<label for="title">Material: </label>
<input name="filename" type="file" required/>
</div>
<div>
<input class="button big primary" name="button" type="submit" value="Add Material"/>
<a class="button big primary" href="module.asp?id=456283123">Done</a>
</div>
</fieldset>
</form>
<div class="progress progress-striped active" id="progressouter" style="width:500px; margin:10px auto;">
<div class="bar" id="progress"></div>
</div>
jQuery的
<script type="text/javascript">
$(document).ready(function(){
//$("#addForm").submit(function() {
var request;
var thispid = "<%=mypid%>";
console.log(thispid);
var progresspump = setInterval(function(){
/* query the completion percentage from the server */
request = $.ajax({
type: "GET",
url: "progress_ajax_update.asp?pid=<%=mypid%>",
dataType: "xml"
});
// callback handler that will be called on success
request.done(function (xml){
$(xml).find('Progress').each(function(){
var elap = $(this).find('ElapsedTime').text();
var rem = $(this).find('RemainingTime').text();
var perc = $(this).find('PercentComplete').text();
var tot = $(this).find('TotalBytes').text();
var upl = $(this).find('UploadedBytes').text();
var rem = $(this).find('RemainingBytes').text();
var spd = $(this).find('TransferSpeed').text();
// log a message to the console
console.log(elap);
console.log(perc);
console.log("progress_ajax_update.asp?pid=<%=mypid%>")
/* update the progress bar width */
$("#progress").css('width',perc+'%');
/* and display the numeric value */
$("#progress").html(perc+'%');
/* test to see if the job has completed */
if(test > 99.999) {
clearInterval(progresspump);
$("#progressouter").removeClass("active");
$("#progressouter").removeClass("progress-striped");
$("#progress").html("Done");
}
});
});
}, 2000);
//});
});
</script>
我在下面的答案中給出了你的線索。試試看,讓我知道。 –