I am using AJAX to asynchronously call a PHP script that returns a large serialized array of JSON objects (about 75kbs or 80k characters). Every time I try and return it it hits a 3000 character limit. Is there a maximum size set anywhere on servers or within jQuery's ajax implementation?
EDIT: the 3'000 limit is a Chrome limit, FF has a 10'000 character limit and Safari has no limit. I'm guessing there is no fix for this apart from changing my code to split/lessen the return data.
You can split your JSON and get with $.ajax part by part
I made an example for you
Html side :
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="jquery.js"></script>
<script>
$(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);
});
});
</script>
</head>
<body>
</body>
</html>
PHP side (file name is x.php) :
<?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);
}
}
?>
Firstly with $.get
(part=size), check how many slices.
Secondly with $.ajax
(part=(int)PART-NUMBER) , in for loop get the parts of JSON one by one
Lastly with $.extend
in for loop marge new getting JSON and old JSON elements in window.result_json
NOTE: $max_of_one
variable determine how many slices to post.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With