Ajax Get site file content instance _ajax related

Source: Internet
Author: User
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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.