我遇到了这个简单的js ajax上传代码($.post由于某种原因,jquery 似乎不适用于HTML5),
/* If you want to upload only a file along with arbitary data that
is not in the form, use this */
var fd = new FormData();
fd.append("file", document.getElementById('file').files[0]);
/* If you want to simply post the entire form, use this */
//var fd = document.getElementById('form1').getFormData();
var xhr = new XMLHttpRequest();
xhr.upload.addEventListener("progress", uploadProgress, false);
xhr.addEventListener("load", uploadComplete, false);
xhr.addEventListener("error", uploadFailed, false);
xhr.addEventListener("abort", uploadCanceled, false);
xhr.open("POST", "Upload.php");
xhr.send(fd);
但是我这里有两个问题,
这条线在物体之后是什么意思FormData?
fd.append("file", document.getElementById('file').files[0]);
为什么在那里需要ID?我能做些什么使用jQuery append() 用$('input[type=file]')?
此ajax仅用于单个文件上传,如何更改多个文件上传?