A simple example of Ajax: Selecting a book will get the relevant name in real time via Ajax.
4 HTML files to the same file on the Web site.
index.html
Copy Code code as follows:
<meta http-equiv= "Content-type" cont Ent= "text/html; Charset=utf-8 ">
<title> a simple Ajax instance that does not involve the server </title>
<script type=" Text/javascript ">
//Declare a variable that references XMLHttpRequest
var xhr = null;
//The function called when selecting a book
function Updatecharacters () {
var selectshow = document.getElementById ("Selshow"). Value;
if (selectshow = = "") {
document.getElementById ("Divcharacters"). InnerHTML = "";
return;
}
//Instantiate a XMLHttpRequest Object
if window. XMLHttpRequest) {
//non ie
XHR = new XMLHttpRequest ();
} else {
//IE
XHR = new ActiveXObject ("Microsoft.XMLHTTP");
}
Xhr.onreadystatechange = CallbackHandler;
URL = selectshow + ". html";
Xhr.open ("post", url, True);
Xhr.send (NULL); The
}
//Is the function that would repeatedly be called by our
//XMLHttpRequest Object DuriNg the life cycle of request
Function CallbackHandler () {
if (xhr.readystate = 4) {
Document.getelement Byid ("Divcharacters"). InnerHTML = Xhr.responsetext;
}
</script> <body>
Our first Ajax instance
<br></br>
Select a masterpiece:
<br>
<select onchange= "updatecharacters ();" id= "Selshow" >
<option value= "" & gt;</option>
<option value= "Xyj" > Journey to </option>
<option value= "HLM" > Dream of Red Mansions </option >
<option value= "Shz" > Marsh </option>
<option value= "Sgyy" > The "All-Kingdoms </option>"
</s Elect>
<br></br>
Returns the main tasks of the classic:
<br>
<div id= "Divcharacters" >
<se Lect>
</select>
</div>
</body>
xyj.html
Copy Code code as follows:
<select>
<option> Tang's monk </option>
<option> Monkey King </option>
<option> Pig </option>
<option> Tang's monk </option>
<option> Kwan-Yin Sister </option>
<option> Buddha </option>
</select>
hlm.html
Copy Code code as follows:
<select>
<option> Jia Baoyu </option>
<option> Lin Daiyu </option>
<option> Xue Chai </option>
</select>
shz.html
Copy Code code as follows:
<select>
<option> Lin Chong </option>
<option> Likui </option>
<option> Song Jiang </option>
<option> Time to move </option>
</select>
sgyy.html
Copy Code code as follows:
<select>
<option> Liu Bei </option>
<option> Guan Yu </option>
<option> Zhang Fei </option>
<option> Caocao </option>
<option> Little Joe </option>
<option> Zhuge Liang </option>
</select>