2012-12-24 60 views
3

我想實現使用一個XMLHttpRequest(進度條視頻上傳)和像這樣的HTML5進度元素:asp.net視頻上傳與進度條

和JS:

public void ProcessRequest (HttpContext context) { 
     var file = context.Request.Files["fu1"]; 
     var savePath = HttpContext.Current.Server.MapPath("~/teees/" + file.FileName); 
     file.SaveAs(savePath); 
     context.Response.ContentType = "text/plain"; 
     context.Response.Write("Hello World"); 
    } 

這個工程網絡:

$("#clicker").live('click', function (e) { e.preventDefault(); UploadVideo("fu1", ""); }); function UploadVideo(elm, url) { var xhr = new XMLHttpRequest(); var fd = new FormData(); fd.append("fu1", document.getElementById("fu1").files[0]); xhr.addEventListener("progress", ProcessVideo, false); xhr.open("POST", "Handler.ashx"); xhr.send(fd); } function ProcessVideo(evt) { if (evt.lengthComputable) { var prog = document.getElementById("prog1"); prog.max = evt.total; prog.value = evt.loaded; } } 

最後我使用這個通用ashx的處理程序處理它ne,但進度條不會將其卡住到零,然後在上載完成時跳到100,那麼問題是什麼?

感謝

回答

0

或許真的在這些線路上?

this.xhr = new XMLHttpRequest(); 
    if (this.xhr){ 
    this.xhr.upload.addEventListener("progress", function(e){ updateProgress(e) }, false); 

    function updateProgress(){ 
    if (e.lengthComputable) { 
     var currentState = (e.loaded/e.total) * 100; 
     //... 
    } 
    }