js上传进度

var updater = null;
var libSuffix = new Array("HDX","JAR");

function startStatusCheck()
{
document.getElementById('status').innerHTML = "";
document.getElementById("a").innerHTML="";
//设置上传按钮为不可用状态,避免多次提交
document.getElementById('submitButton').disabled = true;


//取得文件名
//var element = $("importFile").value;
var element=document.getElementById("importFile").value;
if ((element == "") || (element == "undefine") || (element == null)) {
alert(selectFile);
document.getElementById("submitButton").disabled = false;
return false;
}

var subfix = element.substring(element.lastIndexOf(".")+1).toUpperCase();

if (!isRightSuffix(subfix)) {//扩展名正确
alert(selectPackage);
document.getElementById("submitButton").disabled = false;
return false;
}
lockWindow('MsgWindow');
//创建周期性发送请求的Ajax对象
updater=setInterval("ajax_peroid()",1000);
return true;
}

function ajax_peroid(){
$.ajax({
async:true,
url: 'upload/fileupload',
type: 'get',
dataType: 'html',
cache:false,
data:'c=status',//参数设置
error: reportError,//错误处理,隐藏进度条
success: function(data,evt){
document.getElementById("status").innerHTML=data;
}
});
}

//出错时处理方法
function reportError(request)
{
document.getElementById('submitButton').disabled = false;

document.getElementById('status').innerHTML = '<div class="error"><b>Error communicating with server. Please try again.</b></div>';
document.getElementById('a').innerHTML="<input id=\"buttonok\" type=\"button\" class=\"button\" value=buttonOk οnclick=\"unlockWindow('MsgWindow')\" />";
document.getElementById('buttonok').value=buttonOk;
}


//上传完毕后,取消周期性获取进度状态,将最终的状态显示在客户端
function killUpdate(message)
{
document.getElementById('submitButton').disabled = false;

//停止刷新获取进度
clearInterval(updater);

if(message != '')//如果有错误信息,则显示出来
{
document.getElementById('status').innerHTML = '<div class="error"><b>' + message + '</b></div>';
document.getElementById('a').innerHTML="<input id=\"buttonok\" type=\"button\" class=\"button\" value=buttonOk οnclick=\"unlockWindow('MsgWindow')\" />";
document.getElementById('buttonok').value=buttonOk;
}else{
reloadLib();
}

}

function stopUpdate(message)
{
//停止刷新获取进度
clearInterval(updater);

document.getElementById('status').innerHTML = message;
window.parent.document.location=path+'/home/login.jsp';
}

function reloadLib(){
var url = path + "/admin/DocMgmt.do";
window.location.href=url;
}


//判断扩展名是否正确
function isRightSuffix(subfix)
{
for( var i=0; i<libSuffix.length; i++)
{
if( subfix === libSuffix[i])
{
return true;
}
}
return false;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值