FormData对象发送文件

前端之家收集整理的这篇文章主要介绍了FormData对象发送文件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

function sendForm(){

var oOutput = documeNT.getElemeNTById(“output”);

var oData = new FormData(documeNT.forms.namedItem(“fileinfo”));

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 uploading your file.”;}};

oReq.send(oData);

}

var fd = new FormData(documeNT.getElemeNTById(“fileinfo”));

fd.append(“CustomField”, “this is some extra data”);

$.ajax({

url: “stash.PHP”,

type: “poSt”,

data: fd,

ProCessData: false,

// 告诉jQuery不要去处理发送的数据  

coNTeNTtype: false  

// 告诉jQuery不要去设置CoNTeNT-type请求头});

原文链接:https://www.f2er.com/note/422764.html

猜你在找的程序笔记相关文章