Ajax显示Success而不在internet explorer中提交数据

Ajax showing Success without submitting the data in internet explorer

本文关键字:explorer 提交 数据 internet 显示 Success Ajax      更新时间:2023-09-26

我的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模式下运行。如果您没有明确告诉它使用最新的渲染引擎,这种情况似乎是随机发生的。

将此标记添加到您的,并确保它是块中的第一个标记。

<meta http-equiv="X-UA-Compatible" content="IE=edge" />

这将使IE在最新的渲染引擎中运行。

此外,请确保兼容性模式不会干扰任何内容。