JSON 对象最大大小? [英] JSON object max size?

查看:76
本文介绍了JSON 对象最大大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 jquery,我可以像这样使用 ajax 将 json 对象从客户端发送到服务器:

Using jquery, I'm able to send json objects from client to server using ajax like this:

var strJSON = '{"event":[{
    "dates":[
        "2009-10-14","2009-10-15"],
   "teams":[
        {"id":"0","country":"USA","state":"CA","name":"California Polytechnic State University","subteam":""},
        {"id":"1","country":"USA","state":"CA","name":"California State University, Bakersfield","subteam":""},
        {"id":"2","country":"USA","state":"CA","name":"California State University, Fresno","subteam":""},
        {"id":"3","country":"USA","state":"CA","name":"California State University, Fullerton","subteam":""}]
}]}';

$.ajax({
    url: '../ajax/save_event',
    type: 'POST',
    data: { data : strJSON },
    dataType: 'json',
    timeout: 8000,
    cache: false
});

效果很好.但是如果 JSON 字符串变得更大(不确定确切的大小,但大约 5 倍大),服务器收到的 $_POST 数据是空的.有人知道为什么吗?

It works well. But if the JSON string gets much bigger (not sure the exact size, but somewhere around 5x bigger), the $_POST data received by the server is empty. Anybody know why?

我正在使用 Apache/PHP/jquery.它发生在 IE 和 Firefox 中.是否有需要调整的配置设置?

I'm using Apache/PHP/jquery. It happens from both IE and Firefox. Is there a config setting somewhere I need to adjust?

这是一个无法通过的字符串示例:

Here's an example of a string that fails to make it through:

{"events":[{"dates":["2009-10-10","2009-10-11","2009-10-12"],"divisions":[{"level":"Collegiate","name":"Varsity","subdivision":"Division I","rounds":[],"teams":[{"id":"0","country":"USA","state":"CA","name":"California Polytechnic State University","subteam":""},{"id":"1","country":"USA","state":"CA","name":"California State University, Bakersfield","subteam":""},{"id":"2","country":"USA","state":"CA","name":"California State University, Fresno","subteam":""},{"id":"3","country":"USA","state":"CA","name":"California State University, Fullerton","subteam":""},{"id":"4","country":"USA","state":"CA","name":"Stanford University","subteam":""},{"id":"5","country":"USA","state":"CA","name":"University of California, Davis","subteam":""},{"id":"6","country":"USA","state":"CA","name":"San Francisco State University","subteam":""},{"id":"7","country":"USA","state":"CA","name":"Lassen Community College","subteam":""},{"id":"8","country":"USA","state":"CA","name":"Menlo College","subteam":""},{"id":"9","country":"USA","state":"CA","name":"Fresno Pacific University","subteam":""},{"id":"10","country":"USA","state":"CA","name":"Bakersfield","subteam":""},{"id":"11","country":"USA","state":"CA","name":"Buchanan","subteam":""},{"id":"12","country":"USA","state":"CA","name":"Campolindo-Moraga","subteam":""},{"id":"13","country":"USA","state":"CA","name":"Fremont-Sunnyvale","subteam":""},{"id":"14","country":"USA","state":"CA","name":"Ponderosa-Shingle Springs","subteam":""},{"id":"15","country":"USA","state":"CA","name":"West Covina","subteam":""},{"id":"16","country":"USA","state":"CA","name":"Gilroy","subteam":""},{"id":"17","country":"USA","state":"CA","name":"San José State University","subteam":""},{"id":"18","country":"USA","state":"CA","name":"University of California, Los Angeles","subteam":""},{"id":"19","country":"USA","state":"CA","name":"Sierra College","subteam":""},{"id":"20","country":"USA","state":"CA","name":"Selma","subteam":""},{"id":"21","country":"USA","state":"CA","name":"Liberty","subteam":""}],}]}]}

它是使用 json.org 的stringify"创建的:

It's created using json.org's "stringify":

var strJSON = JSON.stringify(oEvent);

进一步调查后,我将 dataType 更改为text"并尝试发送一长串数字.它一直工作到大约 3500 个字符然后阻塞(当我说阻塞"时,我的意思是请求以空 $_POST 到达服务器.)

Investigating further, I changed the dataType to "text" and tried sending a long string of numbers. It works up until ~3500 characters then chokes (and when I say "choke" I mean that the request arrives at the server with a null $_POST.)

我的 PHP post_max_size 是 64M,所以不是这样.有人建议使用 httpd.conf 中没有的 Apache 的LimitRequestBody",所以我向它添加了LimitRequestBody 0"并重新启动了 Apache.这也没有帮助.

My PHP post_max_size is 64M, so that's not it. Someone suggested using Apache's "LimitRequestBody" which wasn't in httpd.conf, so I added "LimitRequestBody 0" to it and rebooted Apache. That didn't help either.

还有什么建议???

推荐答案

这可能是由于您的服务器配置造成的.检查 php.ini 设置 max_post_size 并确保它足够大以发布您的数据.还要检查您的 Web 服务器设置 - Apache 有一个 LimitRequestBody 指令,这可能会导致您的问题.最后,检查您的网络服务器和 PHP 错误日志,看看大帖子是否触发了任何错误.

This is probably due to your server's configuration. Check php.ini for the setting max_post_size and ensure that it is sufficiently large to post your data. Also check your web server settings - Apache has a LimitRequestBody directive which could be causing your problem. Finally, check your web server and PHP error logs to see if the large post is triggering any errors.

这篇关于JSON 对象最大大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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