我需要发送一个文件(使用AJAX),我需要使用Nginx HttpUploadProgressModule获取文件的上传进度。我需要很好的解决这个问题。我已经尝试过使用jquery.uploadprogress插件,但是我发现自己必须重写大部分内容才能使其在所有浏览器中运行并使用AJAX发送文件。
我需要的只是代码,它需要在所有主流浏览器(Chrome,Safari,FireFox和IE)中运行。如果我能得到一个能处理多个文件上传的解决方案,情况会更好。
发布于 2018-03-31 12:52:43
http://js1.hotblocks.nl/tests/ajax/file-drag-drop.html
基本上它是这样的:
<input id="files" type="file" />
<script>
document.getElementById('files').addEventListener('change', function(e) {
var file = this.files[0];
var xhr = new XMLHttpRequest();
(xhr.upload || xhr).addEventListener('progress', function(e) {
var done = e.position || e.loaded
var total = e.totalSize || e.total;
console.log('xhr progress: ' + Math.round(done/total*100) + '%');
});
xhr.addEventListener('load', function(e) {
console.log('xhr upload complete', e, this.responseText);
});
xhr.open('post', '/URL-HERE', true);
xhr.send(file);
});
</script>
发布于 2018-03-31 14:05:03
以下是使用AJAX上传文件的一些选项:
https://stackoverflow.com/questions/-100007885
复制相似问题