我的ajax代码是
$("#form1").submit(function(e){
var formData = new FormData($(this)[0]);
var ProPicProgressInterval = null;
$.ajax({
url: 'uploader.php',
type: 'POST',
data: formData,
cache: false,
contentType: false,
processData: false,
beforeSend: function(){
ProPicProgressInterval = setInterval(function(){
$.get("progress.php?progress_key=<?php echo $up_id; ?>", function(data){
$("#progressInp").val(Math.round(data)+"%");
}
)},
3000
);
},
success: function(result){
clearInterval(ProPicProgressInterval);
alert(result);
}
});
});
我的 HTML 表单是
<form id="form1" action="" method="POST" onsubmit="return false;">
Choose a file to upload<br />
<!--APC hidden field-->
<input type="hidden" name="APC_UPLOAD_PROGRESS" id="progress_key" value="<?php echo $up_id; ?>"/>
<input name="photo" type="file" /><br />
<input type="text" id="progressInp" value="0%"/><br />
<input name="Submit" type="submit" id="submit" value="Submit" />
</form>
这在除 IE 10 之外的所有浏览器中都可以正常工作。在 Internet Explorer 中,当我们附加文件并单击“提交”时,此警报会在成功功能中显示结果消息,而无需文件传输。我猜是因为 formData 是空的。会出现什么问题?
最佳答案
您的问题可能是因为 IE10 在 Quirks 模式下运行。如果您没有明确告诉它使用最新的渲染引擎,这似乎是随机发生的。
将此标签添加到您的标签中,并确保它是该 block 中的第一个标签。
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
这将使 IE 在最新的渲染引擎中运行。
此外,请确保兼容模式不会干扰任何内容。
关于javascript - Ajax 显示成功,无需在 Internet Explorer 中提交数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25876772/