简体   繁体   English

ajax gzip压缩用于postdata的字符串

[英]ajax gzip compress a string for postdata

Can't seem to find anything related to gzip compressing a string. 似乎找不到与gzip压缩字符串有关的任何内容。 Only find broken sites or suggestions for compressions that won't work as gzip. 仅找到无法使用gzip的损坏站点或压缩建议。 Also lots of talk of server side implementation. 服务器端实现也有很多讨论。 However I wish to send the encoded data from the client. 但是我希望从客户端发送编码后的数据。

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. 为了澄清起见,我所有的客户都使用油腻的monkey或scriptish,而我的所有客户通常都使用最新版本的Firefox或其衍生版本之一,因此每个人的内容编码都不是问题。

What I do need is a pure javascript or some sort of library loadable by javascript to gzip compress a string. 我需要的是纯JavaScript或可通过javascript加载的某种库,以gzip压缩字符串。

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. 刚刚使用https://github.com/dankogai/js-deflate实现了此目的。但是,无论出于何种原因,postdata都会去除+号并将其替换为空格。

To send the data via javascript: 通过javascript发送数据:

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

To receive the data via php: 要通过php接收数据:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM