ITeye博客

js上传进度

ganjuelovejava · 2011-02-18 15:04 · JS · Web前端 · Markdown

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 onclick=\"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 onclick=\"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*) { return true; } } return false; }

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。