I want to use JS from the JSON file to take the value, and output the HTML page, there is a problem

Source: Internet
Author: User
JSON file has multiple 0.json 1.json 2.json 3.json ...

Now the case is that JS can read the contents of the JSON file, but each time the new file is read the contents of the file is gone, I want to load the contents of the new JSON file, keep the previous read the content

Ask the Great God!!!

JS is:

var i = 0; Current file Header
Window.onload = function () {

var host = Window.location.host; Get Domain Name
function GetData () {

Read data by Page Count
var filename = i+ ". JSON";
i++;

$.getjson ("http://bendi.ceshi.com/" +filename, function (data) {
var $content = $ ("#content");
var html = ';
$jsontip. Empty ();//Clear Contents
$.each (data, function (Infoindex, info) {
HTML + = '
      ';
      HTML + = '
    • ';
      HTML + = ";
      HTML + = ";
      HTML + = ";
      HTML + = '

      ' + info[' title "] + '

      ';
      HTML + =";
      HTML + = '
    • ';
      HTML + = '
';
})
$content. HTML (HTML);//Display processed data
})

}

GetData ();

function Scrollhandler () {
$ ("#pullUpB"). Show ();
$ ("#pullUpA"). Hide ();
}

$ ("#pullUpB"). Click (function () {
GetData ();
Scrollhandler ();
});
}


Reply to discussion (solution)

Find the problem append () append new.

$.getjson ("http://bendi.ceshi.com/" +filename, function (data) {
You can save the data to a global array here.

You are covered, you should use append.
$content. HTML (HTML);//Display processed data
Switch
$content. Append (HTML);//Display processed data

$content. HTML (HTML);//Display the processed data traversal once, overwriting the previous thing

Additional use of Append

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.