ajax請(qǐng)求json數(shù)據(jù)案例詳解
今天有這樣一個(gè)需求,點(diǎn)擊六個(gè)大洲,出現(xiàn)對(duì)應(yīng)的一些請(qǐng)求信息,展示在下面,請(qǐng)求請(qǐng)求過(guò)后,第二次點(diǎn)擊就無(wú)需請(qǐng)求。
如圖所示:點(diǎn)擊北美洲下面出現(xiàn)請(qǐng)求的一些數(shù)據(jù)

html代碼結(jié)構(gòu):
<div class="conSixmap">
<div class="name conmap01" data-name="beimeizhou">
<a href="javascript:void(0)">北美洲</a>
<div class="condetail"></div>
</div>
<div class="name conmap02" data-name="nanmeizhou">
<a href="javascript:void(0)">南美洲</a>
<div class="condetail"></div>
</div>
<div class="name conmap03" data-name="ouzhou">
<a href="javascript:void(0)">歐洲</a>
<div class="condetail"></div>
</div>
<div class="name conmap04" data-name="feizhou">
<a href="javascript:void(0)">非洲</a>
<div class="condetail"></div>
</div>
<div class="name conmap05" data-name="yazhou">
<a href="javascript:void(0)">亞洲</a>
<div class="condetail"></div>
</div>
<div class="name conmap06" data-name="dayangzhou">
<a href="javascript:void(0)">大洋洲</a>
<div class="condetail"></div>
</div>
</div>
css樣式:
.conSixmap{position:relative;width:678px;height:335px;margin:0 auto;background:url(../images/tuanduimapBg.png) no-repeat;color:#000;font-family:"微軟雅黑"}
.conSixmap .name .condetail{display:none;position:absolute;z-index:10;width:216px;padding:10px;left:50%;margin-left:-118px;top:54px;background:url(../images/opcity83.png) repeat;border-radius:5px;}
.conSixmap .condetail span{display:block;color:#fff;font-size:14px;text-align:left;}
.conSixmap .name{position:absolute;width:52px;height:55px;}
.conSixmap .name a{display:block;z-index:2;position:absolute;padding-top:35px;text-align:center;cursor:pointer;width:52px;height:20px;color:#000;font-size:12px;}
.conSixmap .conmap01{left:91px;top:73px;}
.conSixmap .conmap01 a{background:url(../images/beimeipicBg.png) no-repeat top center;}
.conSixmap .conmap02 {left:180px;top:213px;}
.conSixmap .conmap02 a{background:url(../images/nanmeimapbg.png) no-repeat top center;}
.conSixmap .conmap03 {left:339px;top:68px;}
.conSixmap .conmap03 a{background:url(../images/ouzhoumapBg.png) no-repeat top center;}
.conSixmap .conmap04{left:327px;top:158px;}
.conSixmap .conmap04 a{background:url(../images/feizhoumapbg.png) no-repeat top center;}
.conSixmap .conmap05 {left:480px;top:75px;}
.conSixmap .conmap05 a{background:url(../images/yazhoumapBg.png) no-repeat top center;}
.conSixmap .conmap06 {left:545px;top:220px;}
.conSixmap .conmap06 a{background:url(../images/dayangmapbg.png) no-repeat top center;}
json格式:
{
"beimeizhou": [
"請(qǐng)求的json數(shù)據(jù)1",
"請(qǐng)求的json數(shù)據(jù)2"
],
"nanmeizhou": [
"請(qǐng)求的json數(shù)據(jù)3",
"請(qǐng)求的json數(shù)據(jù)4"
],
"ouzhou": [
"請(qǐng)求的json數(shù)據(jù)5",
"請(qǐng)求的json數(shù)據(jù)6",
"請(qǐng)求的json數(shù)據(jù)7",
"請(qǐng)求的json數(shù)據(jù)8"
],
"feizhou": [
"請(qǐng)求的json數(shù)據(jù)9",
"請(qǐng)求的json數(shù)據(jù)10",
"請(qǐng)求的json數(shù)據(jù)11",
"請(qǐng)求的json數(shù)據(jù)12"
],
"yazhou": [
"請(qǐng)求的json數(shù)據(jù)13",
"請(qǐng)求的json數(shù)據(jù)14"
],
"dayangzhou": [
"請(qǐng)求的json數(shù)據(jù)15",
"請(qǐng)求的json數(shù)據(jù)16"
]
}
js代碼:
$(document).ready(function(){
//添加地圖
var stauteArr={
'beimeizhou':'true',
'nanmeizhou':'true',
'ouzhou':'true',
'feizhou':'true',
'yazhou':'true',
'dayangzhou':'true'
};
$(".conSixmap .name").on('click',function(){
var _this=this;
var htmlcon="";
$(this).siblings(".name").children(".condetail").fadeOut(500);
$(this).children(".condetail").fadeIn(500);
var _name=$(this).attr('data-name');
$.ajax({
url:"js/schoolMap.json",
type:'get',
data:{},
dataType:"json",
success: function(data){
for(var i in data){
if(_name==i && stauteArr[i]=='true'){
for(var j=0;j<data[i].length;j++){
htmlcon+="<span>"+data[i][j]+"</span>";
}
$(_this).children(".condetail").append(htmlcon);
stauteArr[i]='false';
}
}
},
error: function(){
alert('請(qǐng)求失敗,請(qǐng)檢查網(wǎng)絡(luò)');
}
});
});
});
相關(guān)文章
ajax實(shí)現(xiàn)輸入框文字改變展示下拉列表的效果示例
這篇文章主要介紹了通過(guò)ajax實(shí)現(xiàn)輸入框文字改變展示下拉列表的效果,需要的朋友可以參考下2014-03-03
ajax實(shí)現(xiàn)簡(jiǎn)單實(shí)時(shí)驗(yàn)證功能
這篇文章主要介紹了ajax實(shí)現(xiàn)簡(jiǎn)單實(shí)時(shí)驗(yàn)證功能,需要的朋友可以參考下2017-12-12
天楓AJAX天氣預(yù)報(bào)系統(tǒng)V1.0
天楓AJAX天氣預(yù)報(bào)系統(tǒng)V1.0...2007-02-02
簡(jiǎn)單實(shí)現(xiàn)ajax拖拽上傳文件
這篇文章主要教大家如何簡(jiǎn)單實(shí)現(xiàn)ajax拖拽上傳文件,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-04-04
AJAX的原理—如何做到異步和局部刷新【實(shí)現(xiàn)代碼】
如何做到異步和局部刷新?下面小編就為大家?guī)?lái)一篇AJAX的原理—如何做到異步和局部刷新【實(shí)現(xiàn)代碼】。小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-05-05
Flash & Ajax 操作 XML 實(shí)例:無(wú)刷新分頁(yè)
Flash & Ajax 操作 XML 實(shí)例:無(wú)刷新分頁(yè)...2006-08-08
用AJAX實(shí)現(xiàn)頁(yè)面登陸以及注冊(cè)用戶名驗(yàn)證的簡(jiǎn)單實(shí)例
下面小編就為大家?guī)?lái)一篇用AJAX實(shí)現(xiàn)頁(yè)面登陸以及注冊(cè)用戶名驗(yàn)證的簡(jiǎn)單實(shí)例。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-10-10
layui Ajax請(qǐng)求給下拉框賦值的實(shí)例
今天小編就為大家分享一篇layui Ajax請(qǐng)求給下拉框賦值的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-08-08
AjaxFileUpload+Struts2實(shí)現(xiàn)多文件上傳功能
這篇文章主要介紹了AjaxFileUpload+Struts2實(shí)現(xiàn)多文件上傳功能,需要的朋友可以參考下2017-09-09

