javascript实现AJAX

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
<script language="javascript">
<!--
 var request=false;
 function Text_OnChange()
 {
  var cell=document.createElement("td").appendChild(document.createTextNode("foo"));
  var row=document.createElement("tr").appendChild(cell);
  cell.setAttribute("","");
  document.getElementById("myTableBody").appendChild(row);

  window.alert("ok");
  var spanElement=document.getElementById("mySpan");
  spanElement.style.cssText="font-wight:bold;color:red";
  spanElement.setAttribute("innerHTML","foo");
 }
 function myload()
 {
  
  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="WebForm1.aspx"
  var a=document.getElementById("txta").value;
  var b=document.getElementById("txtb").value;
  request.open("GET",url,true);
  request.onreadystatechange = updatePage;
  request.send(null);
 }

 function updatePage() {
     if (request.readyState == 4)
       if (request.status == 200)
       {
   alert("Server is done!");
   var span=document.getElementById("mySpan");
   span.setAttribute("innerHTML",request.responseText);
  }
       else if (request.status == 404)
         alert("Request URL does not exist");
       else
         alert("Error: status code is " + request.status);
 
   }

//-->
</script>
</head>

<body οnlοad="myload(); return false;2006-2-26">
<table width="141" height="75" border="1" id="myTable">
<tbody id="myTableBody">
<tr><td>sdfd</td></tr>
</tbody>
</table>
<span id="mySpan"></span>
<input type="text" name="txta" id="txta" />
<input type="text" name="txtb" id="txtb" 2006-2-27/>
<input type="button" name="btn" value="click" onClick="getInfo();return false;"/>
</body>
</html> 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值