18Nov

AJAX技术 vs 传统的ASP无刷新技术

使用ajax无刷新技术
ajax.htm

  1. <script>    function f(){  var req =new ActiveXObject("Microsoft.XMLHTTP");  req.open("GET","ajax.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>

1:显示”OK”; 其他字符:显示”Error”

  1. <input id="t1" /> <input type="button" onclick="f();" />

ajax.asp

  1. <!--rResponse.ContentType="text/xml"
  2. if request.querystring("t1")="1" then
  3. response.write("<ok/>")
  4. else
  5. response.write("<error/>")
  6. end if
  7. -->

传统asp无刷新技术
old.htm

  1. <script>    function f(){
  2.  
  3. document.getElementById("o").src="old.asp?t1=" mce_src="old.asp?t1="+t1.value  }</script>

1:显示”OK”; 其他字符:显示”Error”

  1. <input name="1" id="t1" /> <input type="button" onclick="f();" /><iframe src="old.asp" style="display: none" id="o"></iframe>

old.asp

  1. <!--rif request.querystring="" then response.end
  2. end if
  3. if request.querystring("t1")="1" then ss="OK"
  4. -->
  5. <scriptparent.msg.innerText="<%=ss%>"</script>

Leave a Reply