在静态html页面中需要调用动态程序获得的数据 一般采用 ajax技术,本文将 使用asp+jquery+ajax技术获取服务器的时间演示,共分为3个文件,演示如下:
1、asp页面
文件名:(time.asp)
<%=now()&"<br>"%>
2、引用 jquery 文件地址:
<script src="http://code.jquery.com/jquery-1.4.1.min.js"></script>
3、html文件:
文件名:(index.htm)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>jquery+ajax+asp</title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<script src="http://code.jquery.com/jquery-1.4.1.min.js"></script>
<script type="text/javascript">
function tt(){
$.post("time.asp",function(aa,bb){
//alert(aa);
//alert(bb);
if(bb="success"){
//alert(aa);
$(function(){
$("#t1").html(aa);
});
}
else{
alert("ajax失败!")
}
});
setTimeout("tt()",1000);//1秒刷新一次
}
</script>
</head>
<body>
<center><b>jquery+ajax+asp显示时间</b></center>
<br><br><br>
<input type="button" value="查看时间" onclick="tt()"><div id="t1"></div>
</body>
</html>最后一步在 iis 下运行 静态文件 index.htm