I want to use js to take values from the json file and output the html page. I have a problem-php Tutorial

Source: Internet
Author: User
I want to use js to take values from the json file and output the html page. The json file has multiple 0. json 1. json 2. json 3. json...

The current situation is that js can read the content in the json file one by one, but the content of the previous file is gone every time you read the new file. when I want to load the content of the new json file, retain the previously read content

Thank you !!!

Js:

Var I = 0; // The current file header
Window. onload = function (){

Var host = window. location. host; // Get domain name
Function getData (){

// Read data based on the number of pages
Var filename = I + ". json ";
I ++;

$. GetJSON ("http://bendi.ceshi.com/" + filename, function (data ){
Var $ content = $ ("# content ");
Var html = '';
// $ Jsontip. empty (); // clear the content
$. 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)

Locate the problem append () to append the new one.

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

If you overwrite it, you should use append.
$Content.html (html); // Display processed data
Change
$ Content. append (html); // Display processed data

$Content.html (html); // display the processed data and traverse it once to overwrite the previous data.

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.