高普考題庫
106 年 106年公務人員高等考試三級考試暨普通考試・程式設計概要
申論 5AJAX 即「Asynchronous JavaScript and XML」(非同步的JavaScript 與XML 技術)為一重要且普遍用來產生高互動網頁的技術,可讓使用者在執行AJAX 網頁時就像在執行桌上電腦程式(desktop application)一樣順暢(如圖二)。㈠請說明AJAX 三個主要技術為何並說明其目的。(9 分)㈡並請以以下網頁為例,當使用者輸入字元後的網頁反應,說明傳統非AJAX 與AJAX網頁不同之處。(10 分)㈢請說明網頁程式碼中‘xmlhttp.readyState==4’,‘xmlhttp.status==200’及‘"gethint.php?q="+str’代表的意義為何?(6 分)<html lang="en-US"><head><script>function showHint(str){if (str.length==0) {document.getElementById("txtHint").innerHTML=""; return;} else {var xmlhttp=new XMLHttpRequest();xmlhttp.onreadystatechange=function() {if (xmlhttp.readyState==4 && xmlhttp.status==200) {document.getElementById("txtHint").innerHTML=xmlhttp.responseText; }};xmlhttp.open("GET","gethint.php?q="+str, true);xmlhttp.send();}}</script></head><body><div class="w3-example"><h3>Example</h3><form action="javascript:void(0);" class="w3-code-result"><p><b>Start typing a name in the input field below:</b></p><p> Name: <input type="text" id="txt1" onkeyup="showHint(this.value)" size="20">&nbsp;&nbsp;Suggestions: <span id="txtHint"></span> </p></form></div></body></html>圖二、2 個AJAX 範例程式執行結果