Reputation: 11
I have access to a TV Listing API that serves me the data in the form of a compressed XML.gz file that I want to access using javascript AJAX calls.
Whenever I try making AJAX request to the URL, it prompts me to download the file, rather than giving it's contents.
Is there any solution by which I can access the XML content of the file using javascript alone?
Upvotes: 1
Views: 1458
Reputation: 2517
Browsers decompress gzip
files "transparently" on fly. You don't need to set any request header manually for this, browser will automatically add the Accept-Encoding
header as appropriate.
Important : Web server needs to send appropriate response headers for decompression to work, Content-Encoding:gzip
in this case. You can debug Content-Encoding
using Firebug.
You can give a try to this -
$.ajax({
...
headers: { "Accept-Encoding" : "gzip" },
...
});
Upvotes: 5