Jquery 创建用于上载的progressbar
我使用这段代码在asp MVC和jQueryAjax中上传大文件Jquery 创建用于上载的progressbar,jquery,ajax,asp.net-mvc,jquery-ui,Jquery,Ajax,Asp.net Mvc,Jquery Ui,我使用这段代码在asp MVC和jQueryAjax中上传大文件 @section scripts{ <script> $(document).ready(function () { $('#btnUpload').click(function () { UploadFile($('#uploadFile')[0].files); } ) }); function UploadFile(
@section scripts{
<script>
$(document).ready(function () {
$('#btnUpload').click(function () {
UploadFile($('#uploadFile')[0].files);
}
)
});
function UploadFile(TargetFile) {
// create array to store the buffer chunks
var FileChunk = [];
// the file object itself that we will work with
var file = TargetFile[0];
// set up other initial vars
var MaxFileSizeMB = 1;
var BufferChunkSize = MaxFileSizeMB * (1024 * 1024);
var ReadBuffer_Size = 1024;
var FileStreamPos = 0;
// set the initial chunk length
var EndPos = BufferChunkSize;
var Size = file.size;
// add to the FileChunk array until we get to the end of the file
while (FileStreamPos < Size) {
// "slice" the file from the starting position/offset, to the required length
FileChunk.push(file.slice(FileStreamPos, EndPos));
FileStreamPos = EndPos; // jump by the amount read
EndPos = FileStreamPos + BufferChunkSize; // set next chunk length
}
// get total number of "files" we will be sending
var TotalParts = FileChunk.length;
var PartCount = 0;
// loop through, pulling the first item from the array each time and sending it
while (chunk = FileChunk.shift()) {
PartCount++;
// file name convention
var FilePartName = file.name + ".part_" + PartCount + "." + TotalParts;
// send the file
UploadFileChunk(chunk, FilePartName);
}
}
function UploadFileChunk(Chunk, FileName) {
var FD = new FormData();
FD.append('file', Chunk, FileName);
$.ajax({
type: "POST",
url: '/Home/UploadFile/',
contentType: false,
processData: false,
data: FD
});
}
</script>
@节脚本{
$(文档).ready(函数(){
$('#btnUpload')。单击(函数(){
UploadFile($('#UploadFile')[0].files);
}
)
});
函数上载文件(TargetFile){
//创建数组以存储缓冲区块
var FileChunk=[];
//我们将使用的文件对象本身
var file=TargetFile[0];
//设置其他初始变量
var MaxFileSizeMB=1;
var BufferChunkSize=MaxFileSizeMB*(1024*1024);
var ReadBuffer_Size=1024;
var FileStreamPos=0;
//设置初始块长度
var EndPos=缓冲块大小;
var Size=file.Size;
//添加到FileChunk数组,直到到达文件末尾
while(FileStreamPos
我需要为此创建进度条。我如何做?可能重复@BrentBoden谢谢,但我如何将该代码与我的代码匹配?尝试使用此代码上载您的文件@BrentBoden谢谢,但不起作用。您遇到了什么错误,您能显示您尝试的代码吗?