你可以分割你的JSON并逐个获得$.ajax
我为你做了一个例子
Html方面:
Document$(document).ready(function() {
window.result_json = {};
$.get("x.php?part=size",function(data){
var count = data;
for (var i = 0; i <= count; i++) {
$.ajax({
dataType: "json",
url: "x.php",
async: false,
data: "part="+i,
success: function(data){
$.extend(window.result_json,data);
}
});
};
console.log(window.result_json);
});
});
PHP端(文件名是x.php):
if(isset($_GET['part'])){
function send_part_of_array($array,$part,$moo){
echo json_encode(array_slice($array, $part * $moo,$moo,true),JSON_FORCE_OBJECT);
}
$max_of_one = 3;
$a = array("a","b","c","d","e","f","g","h","i","j");
if($_GET['part'] == 'size'){
echo round(count($a) / $max_of_one);
}else{
send_part_of_array($a,$_GET['part'],$max_of_one);
}
}
?>
首先使用$.get(part = size),检查多少个切片.
其次用$.ajax(part =(int)PART-NUMBER),在for循环中逐个获取JSON的部分
最后使用$.extend for for循环marge在window.result_json中获取JSON和旧JSON元素
注意:$max_of_one变量确定要发布的切片数.