如何读取xml。使用javascript ajax请求的gz文件?

时间:2023-01-14 11:45:37

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.

我可以访问一个电视列表API,它以压缩XML的形式为我提供数据。我想使用javascript AJAX调用访问gz文件。每当我尝试向URL发出AJAX请求时,它都会提示我下载该文件,而不是给出它的内容。

Is there any solution by which I can access the XML content of the file using javascript alone?

有什么解决方案可以让我单独使用javascript访问文件的XML内容吗?

1 个解决方案

#1


5  

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.

浏览器在运行时“透明地”解压缩gzip文件。您不需要为此手动设置任何请求头,浏览器将根据需要自动添加接受编码头。


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.

重要提示:Web服务器需要为解压缩发送适当的响应头,这里是Content-Encoding:gzip。您可以使用Firebug调试内容编码。


You can give a try to this -

你可以试试这个-

$.ajax({
  ...
  headers: { "Accept-Encoding" : "gzip" },
  ...
});

#1


5  

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.

浏览器在运行时“透明地”解压缩gzip文件。您不需要为此手动设置任何请求头,浏览器将根据需要自动添加接受编码头。


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.

重要提示:Web服务器需要为解压缩发送适当的响应头,这里是Content-Encoding:gzip。您可以使用Firebug调试内容编码。


You can give a try to this -

你可以试试这个-

$.ajax({
  ...
  headers: { "Accept-Encoding" : "gzip" },
  ...
});