上传大图像时网络连接中止后,恢复或重新启动ajax请求



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

首先我使用离线js 检测到网络关闭或运行良好

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

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

当网络在重新连接后上升时,在上升功能执行操作

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

相关内容

最新更新