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

问题描述

使用jQuery,我可以用ajax这样从客户端发送的JSON对象服务器:

  VAR strJSON ='{事件:[{
    日期:
        2009-10-14,2009-10-15],
   团队:
        {ID:0,国:USA,状态:CA,名:加州州立理工大学,工作小组:},
        {ID:1,国:USA,状态:CA,名:加州州立大学,贝克斯菲尔德,工作小组:},
        {ID:2,国:USA,状态:CA,名:加州州立大学弗雷斯诺,工作小组:},
        {ID:3,国:USA,状态:CA,名:加州州立大学富勒顿,工作小组:}]
}]}';

$阿贾克斯({
    网址:../ajax/save_event,
    键入:POST,
    数据:{数据:strJSON},
    数据类型:JSON,
    超时:8000,
    缓存:假的
});
 

它运作良好。但是,如果JSON字符串获得更大的(不知道确切的尺寸,但地方​​约5倍大),服务器接收到的$ _ POST数据是空的。有人知道为什么吗?

我使用的Apache / PHP / jQuery的。它发生的IE和Firefox浏览器。是否有一个配置设置的地方我需要调整?

下面是一个字符串失败,使其通过一个示例:

<$p$p><$c$c>{"events":[{"dates":["2009-10-10","2009-10-11","2009-10-12"],"divisions":[{"level":"Collegiate","name":"Varsity","subdivision":"Division我,发:[],团队:[{ID:0,国:USA,状态:CA,名:加州州立理工大学 工作小组:},{ID:1,国:USA,状态:CA,名:加州州立大学,贝克斯菲尔德,工作小组: },{ID:2,国:USA,状态:CA,名:加州州立大学弗雷斯诺,工作小组:},{ ID:3,国:USA,状态:CA,名:加州州立大学富勒顿,工作小组:},{ID: 4,国:USA,状态:CA,名:斯坦福大学,工作小组:},{ID:5,国:美国,状态:CA,名:加州大学戴维斯分校,工作小组:},{ID:6,国:USA,状态:CA,名:旧金山州立大学,工作小组:},{ID:7,国:USA,状态:CA, 名:拉森社区学院,工作小组:},{ID:8,国:USA,状态:CA,名:门罗学院,工作小组:},{ID:9,国:USA,状态:CA,名:弗雷斯诺太平洋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泉城,工作小组:},{ID:15,国:USA,状态:CA,名:西Covina","subteam":""},{"id":"16","country":"USA","state":"CA","name":"Gilroy","subteam":""},{"id":"17","country":"USA","state":"CA","name":"San圣何塞州立大学,工作小组:},{ID:18,国:USA,状态:CA,名:加州大学洛杉矶分校 工作小组:},{ID:19,国:USA,状态:CA,名:塞拉利昂College","subteam":""},{"id":"20","country":"USA","state":"CA","name":"Selma","subteam":""},{"id":"21","country":"USA","state":"CA","name":"Liberty","subteam":""}],}]}]}

它使用json.org的字符串创建的:

  VAR strJSON = JSON.stringify(oEvent);
 

编辑:进一步调查,我改变了数据类型设置为文本,并试图发送数字的长字符串。它的工作原理,直到〜3500字符,然后扼流圈(当我说呛我的意思是请求到达服务器与空$ _ POST)

我的PHP的post_max_size为64M,所以这不是它。使用Apache的LimitRequestBody这是不是在httpd.conf有人建议,所以我说LimitRequestBody 0,并重新启动Apache的。这并没有帮助的。

任何其他建议???

解决方案

这可能是由于您的服务器的配置。检查php.ini文件的设置 max_post_size ,并确保它足够大来发表您的数据。另外,请检查你的web服务器设置 - 阿帕奇有一个 LimitRequestBody 指令,它可能会造成您的问题。最后,检查你的web服务器和PHP错误日志,看大岗被触发任何错误。

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
});

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?

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":""}],}]}]}

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

var strJSON = JSON.stringify(oEvent);

EDIT: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.)

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.

Any other suggestions???

解决方案

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对象最大尺寸?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 01:49