参考javascript dom编程艺术一书写的,其中readyStae的5个状态的值的含义如下:
0: (Uninitialized) the send( ) method has not yet been invoked.
1: (Loading) the send( ) method has been invoked, request in progress.
2: (Loaded) the send( ) method has completed, entire response received.
3: (Interactive) the response is being parsed.
4: (Completed) the response has been parsed, is ready for harvesting.
0 - (未初始化)还没有调用send()方法
1 - (载入)已调用send()方法,正在发送请求
2 - (载入完成)send()方法执行完成,已经接收到全部响应内容
3 - (交互)正在解析响应内容
4 - (完成)响应内容解析完成,可以在客户端调用了
更加详尽的内容请参考:[url]http://13521308103.iteye.com/blog/1993394[/url]
0: (Uninitialized) the send( ) method has not yet been invoked.
1: (Loading) the send( ) method has been invoked, request in progress.
2: (Loaded) the send( ) method has completed, entire response received.
3: (Interactive) the response is being parsed.
4: (Completed) the response has been parsed, is ready for harvesting.
0 - (未初始化)还没有调用send()方法
1 - (载入)已调用send()方法,正在发送请求
2 - (载入完成)send()方法执行完成,已经接收到全部响应内容
3 - (交互)正在解析响应内容
4 - (完成)响应内容解析完成,可以在客户端调用了
更加详尽的内容请参考:[url]http://13521308103.iteye.com/blog/1993394[/url]
var xmlHttp,td,text;
function createXMLHttpRequest() {
if (window.ActiveXObject) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}else if (window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
}
}
function subimtForm(){
if(fileSelected()){
createXMLHttpRequest();
document.forms[0].submit();
window.setInterval("setProcessState()", 2000);
document.getElementById("processStateRow").removeAttribute("style");
document.getElementById("processStateRow").setAttribute("style","visibility: visible;");
}
}
function fileSelected(){
if (document.getElementsByTagName("input")[0].value) {
document.getElementsByTagName("a")[0].removeAttribute("onclick");
return true;
} else {
alert("请先选择文件后再导入!");
return false;
}
}
function setProcessState(){
xmlHttp.open("GET", "./getProcessRow", false);
xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState == 4) {
td ? null : td = document.getElementById("processState");
if(isNaN(parseInt(xmlHttp.responseText))){
text = document.createTextNode(xmlHttp.responseText);
td.childNodes[0] ? td.replaceChild(text,td.childNodes[0]) : null;
} else {
text = document.createTextNode("已处理:"+xmlHttp.responseText+" 行");
td.childNodes[0] ? td.replaceChild(text,td.childNodes[0]) : null;
}
}
}
xmlHttp.setRequestHeader('If-Modified-Since', '0');
xmlHttp.send(null);
}