请求不到数据,不知道怎么回事
来源:6-1 实现数据层

慕瓜9363615
2017-11-28
<body>
<div id="root" class="container">
<div class="m-artical-action">
<div class="artical-action-mid" id="action_mid"></div>
</div>
<div id="top-nav" class="top-nav" style="display: none">
<div class="icon-back"></div>
<div class="nav-title">返回书架</div>
</div>
<div id="fiction_chapter_title"></div>
<div id="fiction_container" class="m-read-content">
<h4>雨中的了悟</h4>
<p>
如果雨之後还是雨 如果忧伤之後仍是忧伤 请让我从容面对这别离之後的别离 微笑地继续去寻找一个不可能再出现的 你
</p>
</div>
<div class="m-button-bar">
<div class="u-tab">
<span id="prev_button">上一章</span><span id="next_button">下一章</span>
</div>
</div>
<div id="bottom-nav" class="bottom-nav" style="display: none">
<div class="backg bottom-nav" style="display: none"></div>
<nav>
<div class="content"><img src="img/tree.png" alt=""><span>目录</span></div>
<div class="content" id="content"><img id="font_size" src="img/font_size.png" alt=""><span>字体</span></div> <div class="content" id="content1"><img id="night" src="img/night.png" alt=""><span id="tex">夜间</span></div>
</nav>
</div>
<div class="nav-pannel-bk font-container" style="display: none"></div>
<div class="nav-pannel font-container" id="font-container" style="display: none">
<div class="child-mod">
<span>字号</span>
<button id="large-font" class="font-size-button">大</button>
<button id="small-font" class="font-size-button">小</button>
</div>
<div class="child-mod">
<span>背景</span>
<div class="bk-container">
<div class="bk-container-current"></div>
</div>
<div class="bk-container" style="background:#EBA86C"></div>
<div class="bk-container" style="background:#71B4CB"></div>
<div class="bk-container" style="background:#26C8A5"></div>
<div class="bk-container" style="background:#1A1616"></div>
</div>
</div>
</div>
<script src="js/zepto.js"></script>
<script>
window.jQuery = $
</script>
<script src="js/jquery.base64.js"></script>
<script src="js/jquery.jsonp.js"></script>
<script>
(function(){
var Util=(function(){
var prefix="html5_reader_"
var StorageGetter=function(key){
return localStorage.getItem(prefix+key);
}
var StorageSetter=function(key,val){
return localStorage.setItem(prefix+key,val);
}
var getBSONP=function(url,callback){
return $.jsonp({
url:url,
cache:true,
callback:'duokan_fiction_chapter',
success:function(result){
var data=$.base64.decode(result);
var json=decodeURIComponent(escape(data));
callback(data);
}
})
}
return{
getBSONP:getBSONP,
StorageGetter:StorageGetter,
StorageSetter:StorageSetter
}
})();
var Dom={
top_nav:$('#top-nav'),
bottom_nav:$('.bottom-nav'),
font_container:$('.font-container')
}
var Win=$(window);
var Doc=$(document);
var RootContainer=$('#fiction_container');
var initFontSize=Util.StorageGetter('font_size');
initFontSize=parseInt(initFontSize);
if(!initFontSize){
initFontSize=14;
}
RootContainer.css('font-size',initFontSize);
function main(){
var readerModel= ReaderModel();
readerModel.init();
EventHandler();
}
function ReaderModel(){
//todo 实现和阅读器相关的数据交互的方法
var Chapter_id;
var init=function(){
getFictionInfo(function(){
getCurChapterContent(Chapter_id,function(){
//todo....
})
})
}
var getFictionInfo=function(callback){
$.get('json/chapter.json',function(data){
//todo获得章节信息后的回调用
Chapter_id=data.chapters[1].chapter_id;
callback && callback();
},'json');
}
var getCurChapterContent=function(chapter_id,data){
$.get('json/data'+chapter_id+'.json',function(data){
if(data.result==0){
var url=data.jsonp;
Util.getBSONP(url,function(data){
callback&&callback(data);
});
}
},'json')
}
return {
init:init
}
}
function ReaderBaseFrame(){}
function EventHandler(){
$('#action_mid').click(function(){
if(Dom.top_nav.css('display')=='none'){
Dom.bottom_nav.show();
Dom.top_nav.show();
}else{
Dom.bottom_nav.hide();
Dom.top_nav.hide();
Dom.font_container.hide();
$('#font_size').attr('src',"img/font_size.png");
}
});
$('#content').click(function(){
if(Dom.font_container.css('display')=='none'){
$('#font_size').attr('src',"img/font_size2.png");
Dom.font_container.show();
}else{
Dom.font_container.hide();
$('#font_size').attr('src',"img/font_size.png");
}
})
var i=0;
$('#content1').click(function(){
if(i%2==0){
$('#night').attr('src','img/day.png');
$('#tex').html('白天');
$("body").css('background-color','#1A1616');
i++;
}else if(i%2==1){
$('#night').attr('src','img/night.png');
$('#tex').html('夜间');
$("body").css('background-color','#e9dfc7');
i++;
}
});
$('#large-font').click(function(){
if(initFontSize>20){
return;
}
initFontSize +=1;
RootContainer.css('font-size',initFontSize);
Util.StorageSetter('font_size',initFontSize);
});
$('#small-font').click(function(){
if(initFontSize<12){
return;
}
initFontSize -=1;
RootContainer.css('font-size',initFontSize);
Util.StorageSetter('font_size',initFontSize);
});
function removeCircle(){
$('.bk-container').children('.bk-container-current').remove();
};
$('.bk-container:nth-child(2)').click(function(){
removeCircle();
$("body").css('background-color','#e9dfc7');
$('.bk-container:nth-child(2)').prepend("<div></div>");
$('.bk-container:nth-child(2) div').addClass("bk-container-current");
});
$('.bk-container:nth-child(3)').click(function(){
removeCircle();
$("body").css('background-color','#EBA86C');
$('.bk-container:nth-child(3)').prepend("<div></div>");
$('.bk-container:nth-child(3) div').addClass("bk-container-current");
});
$('.bk-container:nth-child(4)').click(function(){
removeCircle();
$("body").css('background-color','#71B4CB');
$('.bk-container:nth-child(4)').prepend("<div></div>");
$('.bk-container:nth-child(4) div').addClass("bk-container-current");
});
$('.bk-container:nth-child(5)').click(function(){
removeCircle();
$("body").css('background-color','#26C8A5');
$('.bk-container:nth-child(5)').prepend("<div></div>");
$('.bk-container:nth-child(5) div').addClass("bk-container-current");
});
$('.bk-container:nth-child(6)').click(function(){
removeCircle();
$("body").css('background-color','#1A1616');
$('.bk-container:nth-child(6)').prepend("<div></div>");
$('.bk-container:nth-child(6) div').addClass("bk-container-current");
});
Win.scroll(function(){
Dom.bottom_nav.hide();
Dom.top_nav.hide();
Dom.font_container.hide();
$('#font_size').attr('src',"img/font_size.png");
})
}
main();
})();
</script>
</body>
1回答
-
远人
2017-12-14
建议看一下chrome 控制台的network面板,看一下请求的数据是否正常返回了;也可以在请求函数的回调部分打一个debugger断点
00
相似问题