日期:2014-05-16 浏览次数:20871 次
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE>Simple Non-Server AJAX Example</TITLE> <META NAME="Generator" CONTENT="EditPlus"> <META NAME="Author" CONTENT=""> <META NAME="Keywords" CONTENT=""> <META NAME="Description" CONTENT=""> <script> xhr = null; function updateCharacters() { try { if(window.XMLHttpRequest) { //Non-IE. xhr = new XMLHttpRequest(); alert("Non-IE"); } else { //IE xhr = ActiveXObject("Microsoft.XMLHTTP"); alert("IE"); } xhr.onreadystatechange = callbackHandler; url = document.getElementById("selShow").value+".htm"; alert(url); xhr.open('post', url, true); xhr.send(null); } catch (e) { alert("Error: "+e.description); } } function callbackHandler() { alert("cb"); if(xhr.readyState == 4) { document.getElementById("divCharacters").innerHTML = xhr.responseText; } } </script> </HEAD> <BODY> Our first simple AJAX example <br><br> Make a selection here: <br> <select onChange="updateCharacters();" id="selShow"> <option value=""></option> <option value="b5">Babylon 5</option> </select> <br><br> In response, a list of characters will appear here: <br> <div id="divCharacters"> <select></select> <div> </BODY> </HTML>