简单ASP教程:关于AJAX一个的例子

时间:2008-10-07 11:57:51  来源:第二电脑网上收集  作者:

  第二电脑网导读:/><title>AJAX简单应用</title><script language="javascript">//创建XMLHttpRequest对象var request = false;try { request = new XMLHttpRequest();} catch (trymicrosoft) { try { request = new ActiveXObject("Msxml2.XMLHTTP"); } catch (othermicroso...
  正文:

ASP/ target=_blank class=infotextkey>asp教程:关于AJAX一个简单的例子

Index.asp:
程序代码

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>AJAX简单应用</title>
<script language="JavaScript">
//创建XMLHttpRequest对象
var request = false;
try {
 request = new XMLHttpRequest();
} catch (trymicrosoft) {
 try {
 request = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (othermicrosoft) {
 try {
 request = new ActiveXObject("Microsoft.XMLHTTP");
 } catch (failed) {
 request = false;
 }
 }
}
if (!request)alert("Error initializing XMLHttpRequest!");
//获取信息
function getInfo() {
 var url = "info.asp?id=" + Math.random();
 request.open("GET", url, true);
 request.onreadystatechange = updatePage;
 request.send(null);
}
//更新页面
function updatePage() {
 if (request.readyState == 4) {
 if (request.status == 200) {
 var response = request.responseText;
 document.getElementById("div1").innerText = response;
 }else if(request.status == 404) {
 alert ("Requested URL is not found.");
 } else if (request.status == 403) {
 alert("Access denied.");
 } else
 alert("status is " + request.status);
 }
}
</script>
</head>
<body>
<input name="btn" type="button" id="btn" value="获取" onclick="getInfo();" />
<div id="div1">此处显示新 Div 标签的内容</div>
</body>
</html>

Info.asp:
程序代码

<%
Response.Charset = "GB2312" '不设置中文会乱码
Dim i,arr(9)
arr(0) = "随机信息000000000000000000"
arr(1) = "随机信息111111111111111111"
arr(2) = "随机信息222222222222222222"
arr(3) = "随机信息333333333333333333"
arr(4) = "随机信息444444444444444444"
arr(5) = "随机信息555555555555555555"
arr(6) = "随机信息666666666666666666"
arr(7) = "随机信息777777777777777777"
arr(8) = "随机信息888888888888888888"
arr(9) = "随机信息999999999999999999"
Randomize
i = Int(10*Rnd())
Response.write arr(i)
%>

说明:AJAX对服务器返回的结果没有格式上的要求,只需将结果用"Response.write"输出即可。


"简单ASP教程:关于AJAX一个的例子"由第二电脑网原创提供,转载请注明:http://www.002pc.com/master/College/Programming/ASP/2008-10-07/2761.html


关键字:

关于《简单ASP教程:关于AJAX一个的例子》文章的评论

站内搜索: 高级搜索

热门搜索: Windows style 系统 tr IP QQ CPU 安装 function 注册 if td