ajax技术 vs 传统的asp无刷新技术.(转)

来源:互联网 发布:运动软件推广方案 编辑:程序博客网 时间:2024/04/30 19:23

ajax技术  vs  传统的asp无刷新技术.

ajax技术的优势到底在哪里呢,不明白. 看一个最简单的例子

假设用户注册的时候,判断用户输入的名字是否已经被占用.
假设输入
     数字1:显示"OK";   (表示正确,可以使用)
     输入其他字符:显示"Error"  (表示错误,已经被占用)


用ajax技术实现

代码:   t.htm
<script>
function f(){
var req =new ActiveXObject("Microsoft.XMLHTTP");
req.open("GET","t.asp?t1="+t1.value, true);
req.onreadystatechange = function(){
   if (req.readyState == 4) {
      if (req.status == 200) {
          msg.innerText = req.responseXML.documentElement.tagName;
 }
      }
}
req.send(null);
}
</script>
<div>1:显示"OK"; 其他字符:显示"Error"</div>
<input id=t1 value=1>
<input type=button value="检测" onclick="javascript:f()">
<div id=msg></div>


代码:   t.asp
<% 
Response.ContentType="text/xml"
if request.querystring("t1")="1" then
response.write("<OK/>")
else
response.write("<ERROR/>")
end if 
%>

 

------------------------------------------------------------------------------------------
传统的asp无刷新技术

代码t.htm
<script>
function f(){
document.getElementById("o").src="t.asp?t1="+t1.value
}
</script>
<div>1:显示"OK"; 其他字符:显示"Error"</div>
<input id=t1 name=1 value=1>
<input type=button value="检测" onclick="javascript:f()">
<div id=msg></div>
<iframe src="t.asp" style="display:none" id=o></iframe>

 

代码t.asp
<% 
if request.querystring="" then response.end
ss="ERROR"
if request.querystring("t1")="1" then ss="OK"
%>
<script>parent.msg.innerText="<%=ss%>"</script>

 

两者都是无刷新提取服务器(数据库)数据并实时显示在客户段.


那为什么现在都要用 ajax呢,还要考虑中文编码等麻烦问题.

原创粉丝点击