【问题标题】:Get the inner content of a gzipped SVG file with ajax call使用 ajax 调用获取压缩后的 SVG 文件的内部内容
【发布时间】:2018-01-04 23:17:24
【问题描述】:

我正在尝试使用 ajax 调用获取压缩后的 SVG 文件的内容,然后使用 jquery 和 d3.js 控制它的内部元素。现在,我正在将 SVG 文件的所有内部内容打印到 HTML 中,这会导致大量服务器负载。我找不到解决方案。实现它的最佳方法是什么?!

【问题讨论】:

  • 如果 SVG 文件使用正确的标头 (Content-Encoding: gzip) 提供,那么当前端看到它时,它应该是未压缩的。然后只需将 XML 插入 DOM 即可。

标签: javascript jquery ajax d3.js svg


【解决方案1】:

试试这个:

var settings = {
  "async": true,
  "crossDomain": true,
  "url": "http://somewhere.net/file.svg",
  "method": "GET",
  "headers": {
    "cache-control": "no-cache"
  }
}

$.ajax(settings).done(function (response) {
  console.log(response);
});

【讨论】:

    猜你喜欢
    • 2013-07-18
    • 2010-09-19
    • 2017-06-20
    • 2016-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多