Ajax獲得站點(diǎn)文件內(nèi)容的方法教程-創(chuàng)新互聯(lián)

本篇內(nèi)容介紹了“Ajax獲得站點(diǎn)文件內(nèi)容的方法教程”的有關(guān)知識,在實(shí)際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!

成都創(chuàng)新互聯(lián)公司是工信部頒發(fā)資質(zhì)IDC服務(wù)器商,為用戶提供優(yōu)質(zhì)的服務(wù)器機(jī)柜租用服務(wù)

一個簡單的Ajax實(shí)例:選擇一部著作,會通過 Ajax 實(shí)時獲得相關(guān)的名字。

把4個html文件放到 web站點(diǎn) 的同一個文件下。

index.html


復(fù)制代碼 代碼如下:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>一個簡單的不涉及服務(wù)器的Ajax實(shí)例</title>
<script type="text/javascript">
// 聲明一個引用 XMLHttpRequest 的變量
var xhr = null;
// 選擇一個著作時調(diào)用的函數(shù)
function updateCharacters() {
var selectShow = document.getElementById("selShow").value;
if (selectShow == "") {
document.getElementById("divCharacters").innerHTML = "";
return ;
}
// 實(shí)例化一個 XMLHttpRequest 對象
if (window.XMLHttpRequest) {
// 非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);
}
// this is the function that will repeatedly be called by our
// XMLHttpRequest object during the life cycle of request
function callbackHandler() {
if (xhr.readyState == 4) {
document.getElementById("divCharacters").innerHTML = xhr.responseText;
}
}
</script>
</head>
<body>
我們的第一個Ajax實(shí)例
<br></br>
選擇一個名著:
<br>
<select onchange="updateCharacters();" id="selShow">
<option value=""></option>
<option value="xyj">西游記</option>
<option value="hlm">紅樓夢</option>
<option value="shz">水滸傳</option>
<option value="sgyy">三國演義</option>
</select>
<br></br>
返回,名著中主要任務(wù):
<br>
<div id="divCharacters">
<select>
</select>
</div>
</body>
</html>



xyj.html


復(fù)制代碼 代碼如下:

<select>
<option>唐僧</option>
<option>孫悟空</option>
<option>豬八戒</option>
<option>唐僧</option>
<option>觀音姐姐</option>
<option>西天如來</option>
</select>



hlm.html


復(fù)制代碼 代碼如下:

<select>
<option>賈寶玉</option>
<option>林黛玉</option>
<option>薛寶釵</option>
</select>



shz.html


復(fù)制代碼 代碼如下:

<select>
<option>林沖</option>
<option>李逵</option>
<option>宋江</option>
<option>時遷</option>
</select>



sgyy.html


復(fù)制代碼 代碼如下:

<select>
<option>劉備</option>
<option>關(guān)羽</option>
<option>張飛</option>
<option>曹操</option>
<option>小喬</option>
<option>諸葛亮</option>
</select>


“Ajax獲得站點(diǎn)文件內(nèi)容的方法教程”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識可以關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!

本文名稱:Ajax獲得站點(diǎn)文件內(nèi)容的方法教程-創(chuàng)新互聯(lián)
轉(zhuǎn)載源于:http://bm7419.com/article2/gepic.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供關(guān)鍵詞優(yōu)化、企業(yè)網(wǎng)站制作、網(wǎng)站導(dǎo)航、域名注冊、營銷型網(wǎng)站建設(shè)網(wǎng)站改版

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

綿陽服務(wù)器托管