如何从PHP中返回少量的json数据 [英] How to return json data in smaller amounts from PHP

查看:154
本文介绍了如何从PHP中返回少量的json数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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);
});











$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>";



我尝试过的事情:

我有一个很大的json文件,每当我单击按钮时,它都会将大量数据加载到页面上,有什么方法可以仅加载前100个结果,然后在下次单击时加载另外100个结果,依此类推,请,谢谢,使用纯php,javascript,php,json ..没有mysql,没有j查询或其他els之类的框架,只是尝试使用纯语言



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

推荐答案

file = " ;
file = "data.txt";


content = file_get_contents(
content = file_get_contents(


file); // 获取json数据内容
file); //gets json data content


这篇关于如何从PHP中返回少量的json数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆