Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JQuery、AJAX、PHP传递大量数据会导致错误_Php_Jquery_Json_Ajax - Fatal编程技术网

JQuery、AJAX、PHP传递大量数据会导致错误

JQuery、AJAX、PHP传递大量数据会导致错误,php,jquery,json,ajax,Php,Jquery,Json,Ajax,我正在尝试使用AJAX将相当多的数据从页面传递到PHP脚本。这对于一些少量的数据来说效果很好,但是当有更多的数据时会出现以下错误 "PHP Warning: Unknown: Input variables exceeded 1000. To increase the limit change max_input_vars in php.ini. in Unknown on line 0," 我使用的JQuery是: var data = $flowchart.flowchart('getD

我正在尝试使用AJAX将相当多的数据从页面传递到PHP脚本。这对于一些少量的数据来说效果很好,但是当有更多的数据时会出现以下错误

"PHP Warning:  Unknown: Input variables exceeded 1000. To increase the limit change max_input_vars in php.ini. in Unknown on line 0,"
我使用的JQuery是:

var data = $flowchart.flowchart('getData');

$.ajax({
    type: "post", 
    cache: false,
    data: data,
    url: "test.php?name=" +  encodeURIComponent(name) + "&action=" + action,
    success: function(data) {
        console.log (data)
    }
}); 
数据实际上是一个json数据字符串

eg:
sites: 0: {fromOperator: "SiteA", fromConnector: "output_1", fromSubConnector: "0", toOperator: "location1", toConnector: "input_1", …} 1: {fromOperator: "SiteA", fromConnector: "output_2", fromSubConnector: "0", toOperator: "location2", toConnector: "input_1", …} 2: {fromOperator: "start", fromConnector: "output_1", fromSubConnector: "0", toOperator: "SiteA", toConnector: "input_1", …}
并在PHP中读取,只需使用:

// Values from data.
$sites = (isset($_POST['sites']) && count($_POST['sites']) > 0) ? $_POST['sites'] : NULL;
$staff = (isset($_POST['staff']) && count($_POST['staff']) > 0) ? $_POST['staff'] : NULL;
我如何通过
$\u POST['sites']
&
$\u POST['staff']
等方式传递大量数据链接,但仍然在PHP中引用它

我想我需要用JSON做点什么,但我可以解决什么


谢谢

在php标记之后添加开始,希望它能工作

ini_set('max_input_vars', 30000);

我通过在发送数据之前将
JSON.stringify
应用于
数据来实现这一点:

data = encodeURIComponent(JSON.stringify(data))

$.ajax({
    type: "post", 
    cache: false,
    data: 'data=' + data,
    url: "test.php?name=" +  encodeURIComponent(name) + "&action=" + action,
    success: function(data) {
        console.log (data)
    }
}); 
然后在我的PHP中使用:

$js= json_decode($_POST['data'], true);
$staff= (isset($js['sites']) && count($js['sites']) > 0) ? $js['sites'] : NULL;
$staff= (isset($js['staff']) && count($js['staff']) > 0) ? $js['staff'] : NULL;

这似乎和以前一样有效,但允许更大的数据。

通常PHP会对所有请求指定大小限制,PHP.ini文件中设置的
post\u max\u size
是多少?
max\u input\u vars
是1000,
post\u max\u size
是8MBWell,它会告诉您确切的问题甚至解决方案。您发送的字段超过1000个,这是限制,要处理更多字段,您需要增加它。谢谢。我希望这能奏效。。但我不知道我需要的最大限度是多少。有没有更好的方法来发送数据,这样我就不会遇到这个问题了?在限制中加上-1我认为-1对无限限制有效,但不起作用。。max_input_vars的PHP_INI_PERDIR模式是可变的,这意味着不能使用INI_set来更改它