简体   繁体   English

Javascript FormData函数可用于Chrome和Opera,但不适用于Firefox

[英]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.

相关问题 JavaScript搜索功能在Chrome,Safari和Opera中运行良好,但在IE和Firefox中永远存在 - JavaScript search function works great in Chrome, Safari, and Opera, but takes forever in IE and Firefox HTML / JavaScript简单重定向-可以在IE / Opera中运行,但不能在Chrome / Firefox中运行 - HTML/Javascript simple redirect -works in IE/Opera but not in Chrome/Firefox 滚动效果的Javascript代码可在Safari / chrome中运行,而不在Firefox / Opera中运行 - Javascript code for scroll effect works in Safari/chrome, not firefox/opera 该Javascript在IE中不起作用,但在Chrome,Firefox和Opera中起作用 - This Javascript doesn't work in IE but works in Chrome, Firefox and Opera js 代码适用于 firefox 但不适用于 chrome 歌剧和边缘 - a js code works on firefox but not on chrome opera and edge Javascript函数可在chrome和safari中使用,但在Firefox中会中断 - Javascript function works in chrome and safari but breaks in Firefox JavaScript函数不适用于Chrome和IE,但适用于FireFox - JavaScript function not working on Chrome & IE but works on FireFox javascript在chrome / opera / IE中不起作用,但是firefox非常好! - javascript not working in chrome/opera/IE but firefox is excellent! JavaScript可以在Chrome和Firefox中发布/正常运行,但不能在Safari中发布。 在Opera中有趣的作品 - JavaScript will post/work well in Chrome and Firefox, but not Safari. Works funny in Opera Ajax响应中的javascript在Firefox,Chrome,Opera中有效,但不能在Internet Explorer 11中运行-对象不支持此属性或方法 - javascript in ajax response works in Firefox, Chrome, Opera BUT NOT internet explorer 11 - Object does not support this property or method
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM