Resume or restart ajax request after network connection abort while uploading large images?

戏子无情 提交于 2020-01-25 03:12:08

问题


I am trying to upload large files using PLUpload library.at fileUploaded function I have ajax call to upload image to Amazon S3 but ajax call fails prompting error network connection aborted. Please help how to restart or resume my request


回答1:


First I detected the network is down or running perfectly fine using offline js

var run = function(){        
         Offline.check();
    }

    setInterval(run, 3000);

check every 3 seconds network connection available or not.

when network goes up after re-connection perform action at up function

Offline.on('up', function(){
if(ajax_response === null || ajax_response == 'error')
{
    rename_file (oldname,newname)
}
});         

store function parameters as global variables to use it for function call.

    var ajax_response = null;
window.rename_file = function(oldname,newname)
    {
        var resp =null;

        $.ajax({            
            url:'ajaxcall.php',
            data:{action:'rename_file',new_name:newname,old_name:oldname},  
            async:false,            
            success:function(data,status)
            {
                resp = 'success';
            },
            error: function(jqXHR, textStatus, errorThrown) {               
                resp = 'error';                 
            }
        });

        ajax_response.= resp;
        return resp;
    }


来源:https://stackoverflow.com/questions/58975602/resume-or-restart-ajax-request-after-network-connection-abort-while-uploading-la

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!