如何在JavaScript中获取文件值
我试图从HTML上传一个图像,我使用javascript函数检测图像中的变化,然后将其发送到php函数进行上传。我的函数在chrome、firefox、IE10中工作,但在IE9或更早版本中不工作,因为不支持文件API 是否有其他方法可以发送在IE9中工作的文件 我的Javascript如何在JavaScript中获取文件值,javascript,php,jquery,html,Javascript,Php,Jquery,Html,我试图从HTML上传一个图像,我使用javascript函数检测图像中的变化,然后将其发送到php函数进行上传。我的函数在chrome、firefox、IE10中工作,但在IE9或更早版本中不工作,因为不支持文件API 是否有其他方法可以发送在IE9中工作的文件 我的Javascript if (window.FormData) { formdata = new FormData(); } var i = 0, len = this.files.length, img,
if (window.FormData) {
formdata = new FormData();
}
var i = 0, len = this.files.length, img, reader, file;
for ( ; i < len; i++ ) {
file = this.files[i];
if (!!file.type.match(/image.*/)) {
if ( window.FileReader ) {
reader = new FileReader();
reader.onloadend = function (e) {
showUploadedItem(e.target.result, file.fileName);
};
reader.readAsDataURL(file);
}
if (formdata) {
formdata.append("images[]", file);
}
}
}
if (formdata) {
$.ajax({
url: "some URL",
type: "POST",
data: formdata,
processData: false,
contentType: false,
success: function (res) {
document.getElementById("response").innerHTML = res;
}
});
}
if(window.FormData){
formdata=新的formdata();
}
var i=0,len=this.files.length,img,reader,file;
对于(;i
我正在寻找另一种方法来获取文件值并将其发送到变量formdata中
谢谢在IE9及以下版本中,您需要一个隐藏的iframe来提交文件,因为IE不支持formData或文件API。谢谢。你能给我举个例子,说明如何使用iframe获取文件吗?