Victor Kimura
asked on
How to gzip JSON from PHP using AJAX?
Hi,
I'm wondering how I can gzip json data from PHP with an AJAX call.
I was reading here that in PHP 5.4 you can use:
json_encode($data,JSON_UNE SCAPED_UNI CODE);
Unfortunately, I don't have PHP 5.4 installed right now.
So the other user suggested:
ob_start('ob_gzhandler');
But that just doesn't work when I place that code at the top of my PHP file. Server returns error.
I'm looking for an alternative to:
json_encode($data,JSON_UNE SCAPED_UNI CODE);
and also how would I unzip the json data in the $.ajax call:
I'm wondering how I can gzip json data from PHP with an AJAX call.
I was reading here that in PHP 5.4 you can use:
json_encode($data,JSON_UNE
Unfortunately, I don't have PHP 5.4 installed right now.
So the other user suggested:
ob_start('ob_gzhandler');
But that just doesn't work when I place that code at the top of my PHP file. Server returns error.
I'm looking for an alternative to:
json_encode($data,JSON_UNE
and also how would I unzip the json data in the $.ajax call:
$.ajax({
type : 'post',
url: './model/06_modCheckPrimaryBeneficiaries' + sAppendDateTime + '.php',
cache: false,
dataType: 'json',
success: function(retData, textStatus, jqXHR) {
var test = retData;
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
console.log('textStatus: '+textStatus);
});
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok, thanks.
just wondering if you know if this code:
json_encode($data,JSON_UNE SCAPED_UNI CODE);
will make the json data smaller or more efficient then just regular encoding.
just wondering if you know if this code:
json_encode($data,JSON_UNE
will make the json data smaller or more efficient then just regular encoding.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok, I see. How big is too big? I have a some form fields that return in JSON format. The user can add several beneficiaries (it's for estate planning) to this particular page and each beneficiary the user adds increases the JSON by about 24 KB. So, if the user adds in 3 beneficiaries, then that JSON return is about 72 KB. Is that too large? I just want to see how I can optimize the JSON and what's considered too large. I'm trying to see how I can make this more efficient.
Thank you for your input.
Thank you for your input.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks so much for your valuable input. Both of you! =)
Glad we could help. Thanks for the points and thanks for using EE, ~Ray
You're welcome, glad to help.
ASKER
So, this code:
json_encode($data,JSON_UNE
isn't really gzipping it then?
Is that true of some .js files too? I have another post here that you may be able to answer too:
https://www.experts-exchange.com/questions/28313939/gzip-js-not-displaying-in-headers.html