diff --git a/public/download.html b/public/download.html index bd0d4121..a43e07ea 100644 --- a/public/download.html +++ b/public/download.html @@ -23,24 +23,26 @@

点击图片即可下载

table = $("table")[0]; $("a").attr("href", img).attr("download", id); $("img").attr("src", img); -$.get(`data/${target}/${id}.html`, function(result) { - $("table").html(result); - html2canvas(table).then(function(canvas) { - document.body.appendChild(canvas); - var img = new Image(), - url = canvas.toDataURL("image/png"); - img.src = url; - img.onload = function() { - var anchor = document.createElement("a"); - anchor.href = url; - anchor.download = id + "_data"; - document.body.appendChild(anchor); - anchor.appendChild(img); - document.body.removeChild(canvas); - document.body.removeChild(table); - } +fetch(`data/${target}/${id}.html`) + .then(response => response.text()) + .then(result => { + $("table").html(result); + html2canvas(table).then(function(canvas) { + document.body.appendChild(canvas); + var img = new Image(), + url = canvas.toDataURL("image/png"); + img.src = url; + img.onload = function() { + var anchor = document.createElement("a"); + anchor.href = url; + anchor.download = id + "_data"; + document.body.appendChild(anchor); + anchor.appendChild(img); + document.body.removeChild(canvas); + document.body.removeChild(table); + } + }); }); -}); diff --git a/public/index.html b/public/index.html index 20626c33..980ce6ff 100755 --- a/public/index.html +++ b/public/index.html @@ -225,15 +225,9 @@

让撰写《天象预告》实现社会主义四个现代化中技术现代 } function showData(target, type) { - var file = `data/${target}/index.json`; - $.ajax(file, { - type: "get", - dataType: "text", - error: function(xhr, status, error) { - console.log("Error"); - }, - success: function(data, status, xhr) { - var obj = JSON.parse(data); + fetch(`data/${target}/index.json`) + .then(response => response.json()) + .then(obj => { if (type === 0) obj.forEach(function(ele, index) { var html = ` ${ele[property[8]]} @@ -273,8 +267,10 @@

让撰写《天象预告》实现社会主义四个现代化中技术现代 } $("#" + target).append(`${html}`); }); - } - }); + }) + .catch(err => { + console.log("Error"); + }); } for (var i = 0; i < 7; i++) appendThead(); @@ -303,20 +299,21 @@

让撰写《天象预告》实现社会主义四个现代化中技术现代 } function getTable(src) { - return new Promise((resolve, reject) => { - $.get(src, function(result) { + return fetch(src) + .then(response => response.text()) + .then(result => { var table = $(`
`); table.html(result); $("body").append(table); - html2canvas(table[0]).then(function(canvas) { - document.body.appendChild(canvas); - var url = canvas.toDataURL("image/png"); - document.body.removeChild(canvas); - table.remove(); - resolve(``); - }); + return html2canvas(table[0]) + .then(function(canvas) { + document.body.appendChild(canvas); + var url = canvas.toDataURL("image/png"); + document.body.removeChild(canvas); + table.remove(); + return ``; + }); }); - }); } function generate() {