https://www.cnblogs.com/liuxiaohuan/p/9777371.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<textarea name="" id="text" cols="30" rows="10">這里輸入的數據將保存為txt中</textarea>
<script src="lib/jquery-2.1.4.min.js"></script>
<button id="save" type="button">保存</button>
</head>
<body>
<script>
document.querySelector('#save').addEventListener('click', saveFile);
function fakeClick(obj) {
var ev = document.createEvent("MouseEvents");
ev.initMouseEvent("click", true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
obj.dispatchEvent(ev);
}
function exportRaw(name, data) {
var urlObject = window.URL || window.webkitURL || window;
var export_blob = new Blob([data]);
var save_link = document.createElementNS("http://www.w3.org/1999/xhtml", "a")
save_link.href = urlObject.createObjectURL(export_blob);
save_link.download = name;
fakeClick(save_link);
}
function saveFile() {
$.ajax({
contentType: "application/json",
url: "你的url",
type: 'post', //GET
dataType: 'json',
data: JSON.stringify({
regionName: 330681,
pgnum: 1,
pgsize: 10000,
discoveryTime: "2021-12-14"
}),
success: function (res) {
console.log(res);
// let resarr = JSON.stringify( res.data.rows,['latitude','longitude','damageTag','id','degree','deviceName','discoveryTime']);
let resarr = JSON.stringify( res.data.rows);
console.log(resarr);
// var inValue = document.querySelector('#text').value;
exportRaw('test.txt', resarr);
// for (let i of resarr) {
// console.log(i.latitude);
// console.log(i.longitude);
// }
}
})
// var inValue = document.querySelector('#text').value;
// exportRaw('test.txt', inValue);
}
</script>
</body>
</html>
注意這里需要保存為json格式
不然數據多的話保存下來的是
【obj】【obj】這種的了
json轉excel
這種網站有很多
百度一下就行了