<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
<script src="js/ajax.js" type="text/javascript"></script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input id="Button1" type="button" value="从数据库导入到DATATABLE" onclick="Diaoyong(1);" /><br />
<br />
<br />
<input id="Button2" type="button" value="从DATATABLE中导出到EXCEL" onclick="Diaoyong(2);" />
<div id="Xianshi">
</div> //主要代码
</div>
</form>
</body>
</html>
JS 代码
// JScript 文件
var XMLHTTP;
function createXMLHttpRequest() //创建AJAX
{
if(window.ActiveXObject)
{
XMLHTTP=new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest)
{
xmlHttp=new XMLHttpRequest();
}
}
function startRequest(url) //开始AJAX
{
createXMLHttpRequest();
XMLHTTP.onreadystatechange=handleStateChange;
XMLHTTP.open("GET",url,true);
XMLHTTP.send(null);
}
function handleStateChange()
{
if(XMLHTTP.readyState==4) {
alert(XMLHTTP.status); //输出为404 自己没找不到URL问题
if(XMLHTTP.status==200){
PanduanBackZhi();
}
}
}
function PanduanBackZhi()
{
if(XMLHTTP.responseText=="从数据库载出")
{
document.getElementById('Xianshi').innerHTML="<img border=\"0\" src=\"../images/ajaxloading.gif\"><font color=#FF0000 sytle=font-weight:bold>准备从SQL导出数据,请稍等......</font>";
document.getElementById('Button2').disabled=false;
}
if(XMLHTTP.responseText=="从EXCEL 导出")
{
document.getElementById('Xianshi').innerHTML="<img border=\"0\" src=\"../images/ajaxloading.gif\"><font color=#FF0000 sytle=font-weight:bold>准备DATATABLE导出数据,请稍等......</font>";
document.getElementById('Button1').disabled=false;
}
}
function Diaoyong(panduan)
{
startRequest("AJAXExcel.aspx?id="+panduan+"");
}
希望知道的朋友能给个帮助,谢谢!
QQ群:109233721 欢迎您的加入!