国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > AJAX > 正文

通過數(shù)據(jù)庫和ajax方法寫出地圖的實(shí)例代碼

2024-09-01 08:27:40
字體:
供稿:網(wǎng)友

ajax教程

AJAX = Asynchronous JavaScript and XML(異步的 JavaScript 和 XML)。

AJAX 不是新的編程語言,而是一種使用現(xiàn)有標(biāo)準(zhǔn)的新方法。

AJAX 是與服務(wù)器交換數(shù)據(jù)并更新部分網(wǎng)頁的藝術(shù),在不重新加載整個(gè)頁面的情況下。

客戶端部分:html、js、css代碼部分:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd"><html><head><title></title><meta charset="UTF-8"/></head><!--css樣式部分--><style type="text/css">.content_map{/*border:1px solid blue;*/width:1349px;height:524px;float:left;margin-top:100px;}.content_map .mLeft{border:none;border-top:1px solid #fb6c20;width:400px;margin-top:14px;float:left;margin-left:134px;}.content_map>span{margin-left:20px;margin-right:20px;font-size:28px;font-family: "Microsoft Yahei";/*font-weight: bold;*/float:left;}.content_map .mRight{float:left;border:none;border-top:1px solid #fb6c20;width:400px;margin-top:14px;}#maplist{margin-top:50px;width:749px;height:524px;/*border:1px solid #fb6c20;*/background: url("images/diru.png") no-repeat 0 0 ;background-size:contain;position: relative;float:left;}.mapShop img{position:absolute;/*border:1px solid red;*/}#map_right{/*border:1px solid #fb6c20;*/float:left;/*width:600px;*/width:594px;height:524px;background-color: #f0f2fe;margin-top: 40px;}.shopMsg img{width:450px;height:300px;margin-left:72px;margin-top:40px;}.shopMsg .pmname{color:#000;font-size:20px;margin-top:30px;margin-left:72px;font-family:微軟雅黑;}.shopMsg .address{color:#000;font-size:20px;margin-top:30px;margin-left:72px;font-family:微軟雅黑;}.shopMsg .phone{color:#000;font-size:20px;margin-top:30px;margin-left:72px;font-family:微軟雅黑;}</style><body><!--html部分--><div class="content_map"><!-- 標(biāo)題--><hr class="mLeft"/><span>相關(guān)寵物醫(yī)院</span><hr class="mRight"/><!-- 左邊部分:地圖--><div id="maplist"></div><!-- 右邊部分點(diǎn)擊左邊要添加的內(nèi)容:以及最開始加入的信息--><div id="map_right"><div class="shopMsg"><img src="images/w_map.png"/><div class="pmname">寵物店名:Petjoy寵物社區(qū)</div><div class="address">地址:長寧區(qū)機(jī)旋路1258號(hào)--1260號(hào)</div><div class="phone">電話號(hào)碼:(021)53018000</div></div></div></div><!--js代碼部分--><script type="text/javascript">window.onload=function(){getMap();}// 向地圖添加信息:ajaxfunction getMap(){//創(chuàng)建對(duì)象var httpReq;if(window.XMLHttpRequest){httpReq=new XMLHttpRequest();}else{httpReq=new ActiveXObject("Microsoft.XMLHTTP");}var maplist=document.getElementById("maplist");//獲取地圖列表maplist.innerHTML='';//清空地圖里在html里面加的信息// 定義回調(diào)函數(shù),接收從數(shù)據(jù)庫響應(yīng)回來的數(shù)據(jù)。// onreadystatechange():存儲(chǔ)函數(shù)(或函數(shù)名)。每當(dāng)readyState屬性改變時(shí),就會(huì)調(diào)用該函數(shù)httpReq.onreadystatechange=function(){if(httpReq.readyState==4&&httpReq.status==200){var jsonobj=JSON.parse(httpReq.responseText);console.log(jsonobj.length);for (var i = 0; i< jsonobj.length;i++) {maplist.innerHTML+='<div class="mapShop">'+'<img src="images/fi1.png" style="top:'+jsonobj[i].pmTop+"px"+';left:'+jsonobj[i].pmLeft+"px"+'"/>'+'<div id="pmcity'+i+'" onclick="getMessage('+i+')" style="top:'+jsonobj[i].pmTop+"px"+';left:'+jsonobj[i].pmLeft+"px"+';position:absolute;padding-top:20px;'+'">' + jsonobj[i].pmCity + '</div>'+'</div>';}}}//發(fā)起請(qǐng)求(打開一個(gè)地址)httpReq.open("get", "adress.do", true);//發(fā)送,如果提交方式為get,發(fā)送為null;如果提交方式為post,哪send里寫要發(fā)送的參數(shù),沒得的話,就寫nullhttpReq.send(null);}//點(diǎn)擊獲取信息function getMessage(a){console.log("M----------1");var httpReq;if(window.XMLHttpRequest){httpReq=new XMLHttpRequest();}else{httpReq=new ActiveXObject("Microsoft.XMLHTTP");}var map_right=document.getElementById("map_right");map_right.innerHTML='';httpReq.onreadystatechange=function(){if(httpReq.readyState==4&&httpReq.status==200){var jsonobj=JSON.parse(httpReq.responseText);console.log(jsonobj.length);for(var i=0;i<jsonobj.length;i++){map_right.innerHTML+='<div class="shopMsg">'+'<img src="images/'+jsonobj[i].pmImg+'"/>'+'<div class="pmname">寵物店名:'+jsonobj[i].pmName+'</div>'+'<div class="address">地址:'+jsonobj[i].pmAddress+'</div>'+'<div class="phone">電話號(hào)碼:'+jsonobj[i].pmPhone+'</div>'+'</div>'}}}//發(fā)起請(qǐng)求httpReq.open("get", "adressMsg.do?pmId="+a, true);//發(fā)送httpReq.send(null);}</script></body></html>            
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 彭水| 成武县| 沈阳市| 大连市| 浙江省| 芜湖县| 静乐县| 镶黄旗| 凭祥市| 牙克石市| 兴宁市| 呼图壁县| 满洲里市| 吐鲁番市| 神池县| 剑川县| 旺苍县| 临夏县| 北川| 濉溪县| 西宁市| 尤溪县| 团风县| 高阳县| 岳池县| 迁西县| 长兴县| 富民县| 武义县| 郎溪县| 通山县| 城口县| 荥经县| 桦甸市| 温宿县| 钟山县| 平塘县| 新津县| 枝江市| 综艺| 易门县|