2015-10-29 48 views

回答

0

這是我必須知道的上傳進度條功能。很高興,如果這對你有幫助。

$.ajax({ 

    xhr: function() { 
    var xhr = new window.XMLHttpRequest(); 
    xhr.upload.addEventListener("progress", function(evt) { 
     if (evt.lengthComputable) { 
     var percentComplete = evt.loaded/evt.total; 
     percentComplete = parseInt(percentComplete * 100); 
     console.log(percentComplete); 
     if (percentComplete === 100) { 
     } 

     } 
    }, false); 

    return xhr; 
    }, 
    url: posturlfile, 
    type: "POST", 
    data: JSON.stringify(fileuploaddata), 
    contentType: "application/json", 
    dataType: "json", 
    success: function(result) { 
    console.log(result); 
    } 
});