new FormData() 相关用法
Posted 爱我所爱,不负芳华
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了new FormData() 相关用法相关的知识,希望对你有一定的参考价值。
1.simple demo :
var form = document.forms.namedItem("fileinfo");
form.addEventListener(‘submit‘, function(ev) {
var oOutput = document.querySelector("div"),
oData = new FormData(form);//form just origin js object
oData.append("CustomField", "This is some extra data");
var oReq = new XMLHttpRequest();
oReq.open("POST", "stash.php", true);
oReq.onload = function(oEvent) {
if (oReq.status == 200) {
oOutput.innerhtml = "Uploaded!";
} else {
oOutput.innerHTML = "Error " + oReq.status + " occurred when trying to upload your file.<br \/>";
}
};
oReq.send(oData);
ev.preventDefault();
}, false);
2.referer:更复杂的其它方式 上传文件和表单
https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest#Submitting_forms_and_uploading_files
以上是关于new FormData() 相关用法的主要内容,如果未能解决你的问题,请参考以下文章
el-upload 超详细-(附件,图片,多类型文件)玩转上传upload--new FormData()
asp multipart/form-data 怎样传递参数