I'm making an $.ajax call to an endpoint that is responding with gzipped content. For the life of me I cannot figure out how to get it so that the browser sees it that way and can uncompress it. The ajax request I'm making is
$.ajax({
url: 'http://my.server/compressed.html',
method: 'post',
beforeSend: function (request) {
//request.setRequestHeader("Accept-Encoding", "compress, gzip");
},
success: function (data) {
console.log('success', data);
},
error: function ( jqXHR, textStatus, errorThrown ) {
console.log('error', textStatus, errorThrown);
}
});
When the success function is triggered, data is just showing as
���1 �PDѽ�:ޏ�$�+A,D����*��w%���T�9�g���1G����h�6��'�nۖ\����~�%^
As you can see I've tried setting the 'Accept-Encoding' head but the error I'm getting when I do that is Refused to set unsafe header "Accept-Encoding"
. I've tried setting headers on the server side as described in this answer PHP Manual GZip Encoding
but that didn't help me either. I just don't know what I'm missing. What do I need to include in the $.ajax() request (and possibly the server response) to get it so that the success callback has the uncompressed data?
thnx,
Christoph