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 + ='
';
})
$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