Ajax响应大小限制大小、Ajax

2023-09-11 22:30:45 作者:会撩人的粪

我使用AJAX异步调用返回的JSON对象的序列化大阵(约75kbs或80K字)的PHP脚本。每次我尝试并返回它击中一个3000个字符的限制。是否有设置在服务器上或在jQuery的Ajax实现随时随地的最大尺寸是多少?

编辑:3'000限制是一个浏览器限制,FF拥有10000个字符的限制和Safari没有限制。我猜有这个没有修好除了改变我的code分裂/减少返回的数据。

解决方案

您可以分割你的JSON和部分用$阿贾克斯部分

我做了一个例子,你

HTML端:

 <!DOCTYPE HTML>
< HTML LANG =EN>
< HEAD>
    <元的charset =UTF-8>
    <冠军>文件< /标题>
    <脚本SRC =jquery.js和>< / SCRIPT>
    <脚本>
    $(文件)。就绪(函数(){

        window.result_json = {};

       $获得(x.php?部分=尺寸功能(数据){
          VAR数=数据;
          对于(VAR I = 0; I< =计数;我++){
            $阿贾克斯({
              数据类型:JSON,
              网址:x.php
              异步:假的,
              数据:部分=+ I,
              成功:功能(数据){
                $ .extend(window.result_json,数据);
              }
            });
          };
          执行console.log(window.result_json);
       });
    });
< / SCRIPT>
< /头>
<身体GT;

< /身体GT;
< / HTML>
 

PHP端(文件名是x.php):

 < PHP
如果(使用isset($ _ GET ['部分'])){

    功能send_part_of_array($数组,$部分,$哞){
        回声json_en code(array_slice($数组,$部分* $哞,哞$,真正的),JSON_FORCE_OBJECT);
    }
    $ max_of_one = 3;
    $ =一个阵列(一,B,C,D,E,F,G,H,I,J);

    如果($ _ GET ['部分'] =='大小'){
        回声轮(计数($ A)/ $ max_of_one);
    }其他{
        send_part_of_array($ A $ _ GET ['一部分'],$ max_of_one);
    }

}
?>
 
jquery ajax 响应找不到servlet

首先使用 $。获得(部分=大小),检查有多少片。

其次与 $。阿贾克斯(部分=(INT)PART-NUMBER),在for循环中得到JSON之一的部分由一个

最后以 $。延长在for循环玛吉新获得的JSON和 window.result_json

注意: $ max_of_one 变量确定多少片发布

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.