Click here to Skip to main content
15,891,473 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
JavaScript
var btn = document.getElementById("button");
//create an event listener and on click get function to load json data from json file
btn.addEventListener("click", function() {
	var xreq = new XMLHttpRequest();
	var response = document.getElementById("videoObjs");
	xreq.open('GET', 'xjsonData.php', true);
	xreq.onload = function() {
		response.innerHTML += xreq.responseText;  //.php echo saved prints on here
		console.log(response);
	};
	xreq.send(null);
});





PHP
$file = "data.txt";
$content = file_get_contents($file);  //gets json data content
$arr =json_decode($content, true); //converts json to php associative array
print_r($arr);
echo "<br><br>";


What I have tried:

i got large json file, every time i click on button, it s loading the whole large amounts of data onto page, is there any way to load only first 100 results, then on next click to load another 100 results, and so on, please, thanks, with using pure php, javascript, php , json.. no mysql, and no frameworks like j query or anything els, simply trying to use pure languages
Posted
Comments
ilhomelv 2-Feb-18 2:38am    
added a gloal page variable, and a page increment on every call, trying to pass that param thru Get to PHP, now stuck there in PHP

Hide   Copy Code
var page="";var btn = document.getElementById("button");//create an event listener and on click get function to load json data from json filebtn.addEventListener("click", function() {	var xreq = new XMLHttpRequest();	var response = document.getElementById("videoObjs");	xreq.open('GET', 'xjsonData.php?page='+page, true);	xreq.onload = function() {		response.innerHTML += xreq.responseText;  //.php echo saved prints on here		console.log(response);	};	xreq.send(null);	page++; console.log('page '+page);});

$page = $_GET['page'];
$file = "data.txt";
$content = file_get_contents($file);  //gets json data content
$arr =json_decode($content, true); //converts json to php associative array
print_r($arr);
echo "<br><br>";
echo "page: ".$page;
echo "<br><br>";
echo "count: ".count($arr);
echo "<br><br>";


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900