0

I'm trying to fetch XML data but I'm unable to use it as I don't know how to decompress the data. I have two options I can either use GZIP or a ZIP file from the data provider.

$(document).ready(function() {
    $.ajax({
        url:"https://example.xml.gz",
        crossDomain: true,
        success: function(data) {
            console.log(data); 
                 }});
});

I can see the compressed code of the gzipped file in my console returned from the AJAX call but don't know how to decompress it so I can use it in my project.

Could someone show me how to decompress a ZIP or GZIP file following an AJAX request.


I have tried the following solution from stackoverflow Is there a way to parse a zipped XML file with JQuery on the fly?

$(document).ready(function() {
$.ajax({
    url:"https://example.xml.gz",
    beforeSend: function (jqXHR) {
        jqXHR.setRequestHeader('Accept-Encoding', 'gzip');
    },
    crossDomain: true,
    success: function(data) {
        console.log(data); 
             }});
});

This code returns an error in the console...

Attempt to set a forbidden header was denied: Accept-Encoding


I have also tried to set dataType: to "xml" but when I do this instead of seeing the compressed xml data in the console I see.

XML Parsing Error: not well-formed Location: http://192.168.0.11:3000/ Line Number 1, Column 1:

mitchelangelo
  • 779
  • 3
  • 11
  • 36
  • Have you not considered finding a javascript library that can handle .GZ files? The alternative of course, is to implement the DEFLATE algorithm as described by Mark Adddler, yourself. (find a library!) – enhzflep Dec 01 '18 at 22:00
  • I tried pako but it didn't work, could you recommend a library to use? – mitchelangelo Dec 03 '18 at 22:01

0 Answers0