【问题标题】:Ajax upload not working in Firefox and IEAjax 上传在 Firefox 和 IE 中不起作用
【发布时间】:2016-02-08 23:22:07
【问题描述】:

上传按预期工作,但在 Firefox 中没有。没有错误消息,并且帖子设置为回复状态为 200 OK。但是代码在Firefox中停止并且没有上传任何内容。除了状态 200 之外,我没有收到来自服务器的响应

编辑

从 Firefox 发布时 PHP 不会触发 POST 事件;

表格;

<form id="avatar_form" method="post" action="ajax-php.php" enctype="multipart/form-data">
<input id="avatarFile" type="file" name="file" size="25" class="input" value="" data-type="file">
<input id="avatarUp" type="submit" value="Télécharger" disabled="disabled" name="avatarUp">
</form>

在 PHP 之后我可以赶上 POST

if(isset($_POST["avatarUp"])){// deal with the file here}

仅在 Chrome 中。使用 Firefox 时未设置此帖子。

我有这段代码可以使用 ajax 上传文件;

$(document.body).ready(function () {
    $(document.body).on('submit', '#avatar_form', function (e) {
        e.preventDefault(e);
        var $form = $(this);
        var formdata = (window.FormData) ? new FormData($form[0]) : null;
        var data1 = (formdata !== null) ? formdata : $form.serialize();
        alert(data1);

        $.ajax({
            url: $form.attr('action'),
            type: $form.attr('method'),
            contentType: false, 
            processData: false, 
            dataType: 'json', 
            data: data1,
            success: function (response) {
                console.log(response);
                if (response == 1) {
                    var item = load_content('profil_menu').then(function (response) {
                        console.log("Item x", response);
                        data = response;
                        $('#profil_menu').html(data);
                        return;
                    });
                }
            }
        });
    });
});

代码在 Chrome 中运行良好但在 FirexFox 或 IE 中不行,我不太关心 IE 但它应该在 Firefox 中运行?

那么这篇文章有什么问题?

【问题讨论】:

    标签: jquery ajax firefox upload


    【解决方案1】:

    通过设置async : false 使您的ajax 调用同步。这必须做的工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-01-04
      • 1970-01-01
      • 2011-08-03
      • 2012-10-18
      • 2017-03-08
      • 1970-01-01
      • 2014-01-14
      相关资源
      最近更新 更多