FormData不能附加文件对象 [英] FormData cannot appended with File Object

查看:379
本文介绍了FormData不能附加文件对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用AJAX上传图像,但是当我尝试向FormData添加文件对象时,这在我的代码中不起作用

Hi i am trying to upload image using AJAX but when i try to append FormData with my file object it didn't work here is my code

var data = new FormData();
$.each(files, function(key, value){
    console.log(value);
    data.append(key, value);
    console.log(data);
});

在控制台中,我得到了这个响应

and in console i got this response

File { size=1626773, type="text/comma-separated-values",    name="Prepaid_Rates_01.03.2014.csv", more...}
uploadrates.js (line 17)
FormData { append=append()}

在这里您可以看到文件显示在控制台中,但追加后在数据中不可用

here u can see that File is shown in console but not available in data after append

我也看到了这类问题,但是找不到任何合适的答案

i also see this type of questions but not find any proper answer that works

推荐答案

存在使用较旧的jquery版本文件并替换为最新版本的问题. 这是旧的jQuery

there was a problem of using older jquery version file and by replacing with the latest do the job. here is the old jquery

<script src="jquery-1.4.4.js"></script>

,新的jquery文件为:

and the new jquery file is as:

<script src="jquery-1.11.0.min.js"></script>

我不知道两个文件中的更改,但是当我尝试使用最新版本时,它允许我上传文件,现在我证明使用最新版本更好,并尝试使用最新版本;

i have no idea of the changes in both files but when i try the latest version it allow me to upload the file and now i prove that the latest versions are better to use and try to use the latest version;

这篇关于FormData不能附加文件对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆