简体   繁体   中英

Ajax upload not working in Firefox and IE

The upload work as intended but not in firefox. There is no error msg and the post is set with a reply status of 200 OK. But the code stop in firefox and nothing get uploaded. I get no response from server beside status 200

EDIT

The POST event is not getting triggered by PHP when posted from Firefox;

The form;

<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>

After that in PHP I can catch the POST

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

Only in Chrome. This post is not set when using Firefox.

I have this code to upload files using 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;
                    });
                }
            }
        });
    });
});

The code is working fine in Chrome But not in FirexFox or IE, I dont care much about IE but it should work in Firefox?

So What is wrong with this Post?

Make your ajax call synchronous by setting async : false . This must do the job.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM