2 years ago

#62391

test-img

Ebr Mo

Resume the Ajax upload form when the Internet is connected

When the user's internet is connected, the upload is done and while uploading, the internet is suddenly disconnected and the form upload is failed.(status = (failed)net::ERR_INTERNET_DISCONNECTED , Type = xhr)

Is there a code that resumes the upload form after connecting to the Internet?

This is my upload code that is sent as Ajax:

$('#form_upload_create').submit(function (e) {
e.preventDefault();
$form = $(this)
var formData = new FormData(this);
$.ajax({
    url: window.location.pathname,
    type: 'POST',
    data: formData,
    cache: false,
    contentType: false,
    processData: false,
    success: function (response) {
           alert(response.message)
        }
    },
    xhr: function () {
        //upload Progress
        var xhr = $.ajaxSettings.xhr();
        if (xhr.upload) {
            xhr.upload.addEventListener('progress', function (event) {
                var percent = 0;
                var position = event.loaded || event.position;
                var total = event.total;
                if (event.lengthComputable) {
                    percent = Math.ceil(position / total * 100);
                }
                //update progressbar
                $(".progress-bar").css("width", +percent + "%");
                $(".status").text(percent + "%" + 'waiting upload...');
            }, true);
        }
        return xhr;
    },
});

});

javascript

ajax

upload

resumable

0 Answers

Your Answer

Accepted video resources