ajax+servlet实现进度条
业务逻辑:在web应用建立进度条。
页面:progressBar.jsp
<%@ page contentType="text/html; charset=GBK" %>
<html>
<head>
<title>
Ajax进度条
</title>
<script type="text/javascript">
//xmlHttpRequest对象
var xmlHttp;
var key;
//进度条颜色
var bar_color='gray';
var span_id='block';
var clear=" "
//创建xmlHttpRequest对象
function createXMLHttpRequest(){
if (window.ActiveXObject){
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest();
}
}
//执行方法
function go(){
createXMLHttpRequest();
checkDiv();
var url = "ProgressBarServlet?task=create";
//隐藏按钮
var button = document.getElementById("go");
button.disabled = true;
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange = goCallback;
xmlHttp.send(null);
}
//回调方法
function goCallback(){
if (xmlHttp.readyState == 4){
if (xmlHttp.status == 200){
//设置更新时间
setTimeout("pollServer()",2000);
}
}
}
&nbs