Ajax有待學習,權當筆記吧.
上例子
根目錄下txt檔案內容:apple banana pear
html代碼如下:
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <title></title> 5 <script type="text/javascript"> 6 function gettext() { 7 var xmlhttp;//定義 8 if (window.XMLHttpRequest) { 9 //建立XMLHttpRequest(IE7+、Firefox、Chrome、Safari、Opera)10 xmlhttp = new XMLHttpRequest();11 }12 else {13 //IE5 and IE614 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");15 }16 xmlhttp.onreadystatechange = function () {17 if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {18 document.getElementById("showtext").innerHTML = xmlhttp.responseText;19 }20 21 }22 xmlhttp.open("GET", "/test.txt", true);//向伺服器發送請求23 xmlhttp.send();24 25 }26 </script>27 </head>28 <body>29 <input id="btn1" type="button" value="get擷取" onclick="gettext()" />30 <div id="showtext"></div>31 </body>32 </html>
顯示結果:
先暫時結束吧!