日期:2014-05-16 浏览次数:20456 次
<!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=GB18030"> <title>第一个ajax例子</title> <script type="text/javascript" > function Ajax(){ var xmlHttpReq = null; if(window.ActiveXObject){ xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP"); }else if(window.XMLHttpRequest){ xmlHttpReq = new XMLHttpRequest(); } if(xmlHttpReq){ xmlHttpReq.open("GET","test.php",true); xmlHttpReq.onreadystatechange = requestCallBack; xmlHttpReq.send(null); } function requestCallBack(){ if(xmlHttpReq.readysate == 4){ if(xmlHttpReq.status == 200){ document.getElementbyId("resText").innerHTML = xmlHttpReq.responseText; } } } } </script> </head> <body> <input type="button" value="Ajax提交" noclick="Ajax()"/> <div id="resText"></div> </body> </html>