【问题标题】:Ajax showing Success without submitting the data in internet explorerAjax 显示成功,但未在 Internet Explorer 中提交数据
【发布时间】:2014-09-16 19:19:59
【问题描述】:

我的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 是空的。会有什么问题?

【问题讨论】:

  • 您是否尝试过在 submit() 的末尾也返回 false ?
  • 试过了,但没用
  • 还有一件事,即使 IE10 支持 formData,formData 也肯定是空的。

标签: javascript jquery html ajax internet-explorer


【解决方案1】:

您的问题可能是因为 IE10 在 Quirks 模式下运行。如果您没有明确告诉它使用最新的渲染引擎,这似乎是随机发生的。

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

&lt;meta http-equiv="X-UA-Compatible" content="IE=edge" /&gt;

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

另外,请确保兼容模式不会干扰任何事情。

【讨论】:

  • 很遗憾,没有解决问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-02-21
相关资源
最近更新 更多