主頁(yè) > 知識(shí)庫(kù) > ajax實(shí)現(xiàn)點(diǎn)擊不同的鏈接讓返回的內(nèi)容顯示在特定div里

ajax實(shí)現(xiàn)點(diǎn)擊不同的鏈接讓返回的內(nèi)容顯示在特定div里

熱門標(biāo)簽:科大訊飛語(yǔ)音識(shí)別系統(tǒng) 銀行業(yè)務(wù) 團(tuán)購(gòu)網(wǎng)站 Linux服務(wù)器 服務(wù)器配置 Mysql連接數(shù)設(shè)置 阿里云 電子圍欄

/* 以下代碼通過(guò)ajax實(shí)現(xiàn)在一個(gè)web頁(yè)面點(diǎn)擊不同的鏈接,然后將返回的結(jié)果顯示在該頁(yè)面固定的div里。 */

html> 
head> 
meta charset="UTF-8"> 
title>Insert title here/title> 
script language="javascript"> 
var http_request = false; 
function createRequest(url,objID){ 
http_request = false; 
if(window.XMLHttpRequest){ //非IE瀏覽器 
http_request = new XMLHttpRequest(); 
if(http_request.overrideMimeType){ 
http_request.overrideMimeType("text/xml"); 
} 
}else if(window.ActiveXObject){ //IE瀏覽器 
try{ 
http_request = new ActiveXObject("Msxml2.XMLHTTP"); 
}catch(e){ 
try{ 
http_request = new ActiveXObject("Microsoft.XMLHTTP"); 
}catch(e){} 
} 
} 
if(!http_request){ 
alert("無(wú)法創(chuàng)建XMLHTTP實(shí)例"); 
return false; 
} 
http_request.open("GET",url,true); 
http_request.send(null); 

var obj = document.getElementById(objID); 
http_request.onreadystatechange = function(){ 
if(http_request.readyState == 4){ 
if(http_request.status == 200){ 
obj.innerHTML = http_request.responseText; 
}else{ 
alert('您請(qǐng)求的頁(yè)面發(fā)現(xiàn)錯(cuò)誤!'); 
} 
} 
} 
} 
/script> 
/head> 

body onload="createRequest('content1.html','show')"> 
div align="center"> 
a href="content1.html" onclick="createRequest('content1.html','show');return false;">no1/a> | 
a href="content2.html" onclick="createRequest('content2.html','show');return false;">no2/a> | 
a href="content3.html" onclick="createRequest('content3.html','show');return false;">no3/a> 
/div> 
div id="show" align="center">/div> 
/body> 
/html>
您可能感興趣的文章:
  • Jquery實(shí)現(xiàn)遮罩層的簡(jiǎn)單實(shí)例(就是彈出DIV周圍都灰色不能操作)
  • js實(shí)現(xiàn)的點(diǎn)擊div區(qū)域外隱藏div區(qū)域
  • 點(diǎn)擊頁(yè)面其它地方隱藏該div的兩種思路
  • 將兩個(gè)div左右并列顯示并實(shí)現(xiàn)點(diǎn)擊標(biāo)題切換內(nèi)容
  • 基于JS實(shí)現(xiàn)彈出一個(gè)隱藏的div窗口body頁(yè)面變成灰色并且不可被編輯

標(biāo)簽:蚌埠 廣元 江蘇 衢州 萍鄉(xiāng) 大理 棗莊 衡水

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《ajax實(shí)現(xiàn)點(diǎn)擊不同的鏈接讓返回的內(nèi)容顯示在特定div里》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266