ajax gzip压缩用于postdata的字符串 [英] ajax gzip compress a string for postdata

查看:492
本文介绍了ajax gzip压缩用于postdata的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎找不到与gzip压缩字符串有关的任何内容.只找到无法用作gzip的破碎站点或压缩建议.服务器端实现也有很多讨论.但是我希望从客户端发送编码后的数据.

Can't seem to find anything related to gzip compressing a string. Only find broken sites or suggestions for compressions that won't work as gzip. Also lots of talk of server side implementation. However I wish to send the encoded data from the client.

为澄清起见,我所有的客户都使用油腻的猴子或脚本语言,并且我的所有客户通常都使用最新版本的Firefox或其衍生版本之一,因此每个人的内容编码都不是问题.

To give clarification all my clients use greasemonkey or scriptish and all my clients are generally on some version of a recent Firefox or one of it's derivatives, so content encoding for everyone is not an issue.

我需要的是纯JavaScript或可通过javascript加载的某种库,以gzip压缩字符串.

What I do need is a pure javascript or some sort of library loadable by javascript to gzip compress a string.

推荐答案

只需使用 https://github.com/dankogai/js-deflate 但是,无论出于何种原因,postdata都会去除+号并将其替换为空格.

Just achieved this using https://github.com/dankogai/js-deflate However the postdata for whatever reason will strip the + signs and replace them with spaces.

要通过javascript发送数据:

To send the data via javascript:

params.mapdata= btoa(RawDeflate.deflate(JSON.stringify(mapdata))); 

要通过php接收数据:

To receive the data via php:

$value = gzinflate(base64_decode(preg_replace('/\s/', '+',$value))); 

这篇关于ajax gzip压缩用于postdata的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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