weixin_33735077 2014-11-16 10:20 采纳率: 0%
浏览 67

用PHP压缩JSON响应

I've a simple MVC model. I'm doing an Ajax request where I send some data to be processed by PHP and retrieve database records as JSON. As this object could be quite large, is there some way I could compress/encrypt it on the PHP (server side) and decrypt it on the Javascript side (client)

$.ajax({
    url: "/php/function/link/",
    dataType: 'json',
    data: {
            "date": date,
          },
    type: "POST", 
    success: function(_data){
              // load encrypted data here and decrypt it.
          },
    error: function() {
       alert("Some error fetching!");

    }

I tried using the following methods, but they didn't seem to work (I was getting error while decompressing them on the javascript end):

  1. JSONC
  2. https://stackoverflow.com/a/11901649/1443702

Are there any other better ways? I simply need to :

compress data on javascript to be passed from client->send it to server (PHP) -> decompress it and compute database queries -> compress it -> pass it to javascript(client side) -> decompress it

  • 写回答

2条回答 默认 最新

  • weixin_33696822 2014-11-16 10:24
    关注

    The best way is just to enable HTTP traffic compression in web server. All modern browsers and servers support it. Read more about HTTP_compression. And you will have additional bonus: all your traffic will be compressed, not AJAX traffic only.

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度