Skip to content
This repository has been archived by the owner on Apr 25, 2024. It is now read-only.

Commit

Permalink
Drop $.ajax
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenjoezhang committed Oct 26, 2022
1 parent 776ea1e commit e4283b3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 38 deletions.
36 changes: 19 additions & 17 deletions public/download.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,26 @@ <h1>点击图片即可下载</h1>
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);
}
});
});
});
</script>
</body>
</html>
39 changes: 18 additions & 21 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,9 @@ <h2>让撰写《天象预告》实现社会主义四个现代化中技术现代
}

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 = `<td><input type="checkbox" class="${target}" id="${ele[property[9]]}"></td>
<td>${ele[property[8]]}</td>
Expand Down Expand Up @@ -273,8 +267,10 @@ <h2>让撰写《天象预告》实现社会主义四个现代化中技术现代
}
$("#" + target).append(`<tr>${html}</tr>`);
});
}
});
})
.catch(err => {
console.log("Error");
});
}

for (var i = 0; i < 7; i++) appendThead();
Expand Down Expand Up @@ -303,20 +299,21 @@ <h2>让撰写《天象预告》实现社会主义四个现代化中技术现代
}

function getTable(src) {
return new Promise((resolve, reject) => {
$.get(src, function(result) {
return fetch(src)
.then(response => response.text())
.then(result => {
var table = $(`<table class="standardTable"></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(`<img src="${url}">`);
});
return html2canvas(table[0])
.then(function(canvas) {
document.body.appendChild(canvas);
var url = canvas.toDataURL("image/png");
document.body.removeChild(canvas);
table.remove();
return `<img src="${url}">`;
});
});
});
}

function generate() {
Expand Down

0 comments on commit e4283b3

Please sign in to comment.