【问题标题】:Resume or restart ajax request after network connection abort while uploading large images?上传大图像时网络连接中止后恢复或重新启动ajax请求?
【发布时间】:2019-11-21 12:56:06
【问题描述】:

我正在尝试使用 PLUpload library.at fileUploaded 函数上传大文件我有 ajax 调用将图像上传到 Amazon S3 但 ajax 调用失败,提示错误网络连接中止。 请帮助如何重新启动或恢复我的请求

【问题讨论】:

    标签: ajax amazon-s3 restart plupload abort


    【解决方案1】:

    首先,我使用 offline js 检测到网络已关闭或运行良好

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

    每 3 秒检查一次网络连接是否可用。

    当网络重新连接后,在 up 函数中执行操作

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

    将函数参数存储为全局变量以用于函数调用。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-19
      • 1970-01-01
      • 1970-01-01
      • 2011-05-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多