Home  >  Article  >  Backend Development  >  小弟我要用js从json文件中取值,并输出的html页面,有个有关问题

小弟我要用js从json文件中取值,并输出的html页面,有个有关问题

WBOY
WBOYOriginal
2016-06-13 12:27:22747browse

我要用js从json文件中取值,并输出的html页面,有个问题
json文件有多个  0.json  1.json  2.json  3.json ...

现在的情况是js可以挨个读取json文件中的内容,但是每次读取新文件的时候之前的文件内容就没了,我想要加载新json文件内容时,保留之前的读出来的内容

求大神!!!

js 为: 

var i = 0; //当前文件头部
window.onload = function () {

    var host = window.location.host; //获取域名
    function getData() {

        //根据页数读取数据
        var filename = i+".json";
        i++;

        $.getJSON("http://bendi.ceshi.com/"+filename, function (data) {
            var $content = $("#content");
                var html ='';
            //  $jsontip.empty();//清空内容
            $.each(data, function (infoIndex, info) {
                html += '

';
            })
            $content.html(html);//显示处理后的数据
        })

    }

    getData();

    function scrollHandler() {
        $("#pullUpB").show();
$("#pullUpA").hide();
    }

    $("#pullUpB").click(function () {
        getData();
        scrollHandler();
    });
}


------解决思路----------------------
你是覆盖了,应该使用追加。
$content.html(html);//显示处理后的数据
改为
$content.append(html);//显示处理后的数据
------解决思路----------------------
 $content.html(html);//显示处理后的数据  遍历一次,把之前的东西覆盖掉了

追加使用append
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn