dongxun8189 2014-07-09 15:35
浏览 59

如何通过AJAX使用jQuery和PHP处理海量数据?

i am passing a huge javascript array to php via the $.ajax method of jquery. The Content-Type is JSON and i sent the data as RAW.

In PHP i get the data with file_get_contents('php://input').

Everything is working very well, but on huge javascript arrays, for example 2,5MB, php receives only the small vars and the huge vars are stripped out. Before i send the data with jquery i do a JSON.stringify to send the data as JSON. PHP still will strip out all huge vars in this JSON string and if i get the contents of "php://input" only the small vars are left over....

In the php.ini i have raised up the max_post_size and other stuff, but nothing will work...

Does anybody know how i can handle this right?

thx!

  • 写回答

1条回答 默认 最新

  • 普通网友 2014-07-09 15:51
    关注

    Probably not the best idea but you could split your data, somthing like (not tested, might need a few corrections):

    var json = HUGEJSON;
    while (json.length != 0) {
       var toSend = json.length >= 4096 ? json.substr(0, 4096) : json;
       $.ajax({
           url: 'server',
           method:'post',
           type:'json',
           data: toSend
       });
       json = json.length >= 4096? json.substr(4096, json.length-4096) : json;
    }
    

    Then find a way to rebuild the data server side until all the data have been send.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题