[英]Javascript FormData function works with Chrome and Opera but not Firefox
var data = new FormData(document.getElementById("uploadform"));
$.each($('#file')[0].files, function(i, file) {
data.append('file-'+i, file, this.name);
});
That code works on Chromium 26 but not Firefox 21. I put an alert within the each loop, "alert(this.name)", which displays the filename in Chrome, but nothing in Firefox...so that's apparently where it's all bogging down in Firefox. 该代码在Chromium 26上有效,但在Firefox 21上无效。在Firefox中。
I also tried it on Firefox 24--same problem. 我也在Firefox 24上尝试过同样的问题。 I know this code used to work on Firefox--an older version than 21. 我知道这段代码曾经在Firefox上运行,而Firefox的版本早于21。
This slight change, just leaving off a couple parameters, gives me the same results: 略有更改,只留下了几个参数,给了我相同的结果:
var data = new FormData();
$.each($('#file')[0].files, function(i, file) {
data.append('file-'+i, file);
});
I just have no idea what's up, because Mozilla docs show that this is supported and that I'm doing it right. 我只是不知道这是怎么回事,因为Mozilla文档显示此功能受支持并且我做对了。
Here's the ajax call portion of the code if anyone curious (but this is not the problem--it's bogging down in the above code per my alert check): 如果有人好奇,这是代码的ajax调用部分(但这不是问题-根据我的警报检查,它在上面的代码中陷入了困境):
$.ajax({
url: 'upload.php',
data: data,
contentType: false,
processData: false,
cache: false,
type: 'POST',
success: function(data){ }
Anyone have any similar problems, or have any inkling where to even look? 任何人都有任何类似的问题,或者在哪里寻找任何暗示?
Are there errors in your browser's console? 浏览器的控制台中是否有错误? Check the Net (or Network) tab as well. 还要检查“网络(或网络)”选项卡。
I would test in IE or Opera as well to confirm that it is specifically a FF issue. 我也会在IE或Opera中进行测试,以确认这是FF问题。
Also try producing an alert 也尝试产生警报
if (!window.FormData) {
alert('Doh!');
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.