我是从 [Asm] 纯文本查看 复制代码 https://timor.tech/api/holiday/year/2024 获取的数据
以下是我把它转存到自己数据库的代码
[Asm] 纯文本查看 复制代码 function getHoliDateByAPI() {
$.ajax({
url: "https://timor.tech/api/holiday/year/2024",
type: "GET",
dataType: "json",
success: function (_data) {
//console.log(_data);
var _dates = [];
for (var _time in _data.holiday) {
//console.log(_time);
var _date = _data.holiday[_time];
// console.log(_date);
var _o = { holiday: _date.holiday, info: _date.name, date: _date.date, replaceDate: "" };
_dates.push(_o);
}
saveHoliDate(_dates);
}
})
}
function saveHoliDate(_data) {
$.ajax({
url: "https://我的数据地址/holiday/",
type: "POST",
dataType: "json",
data: { type: "addHoliDay", data: JSON.stringify(_data) },
success: function (_d) {
console.log(_d);
}
})
}
function init() {
getHoliDateByAPI();
}
if (typeof $ == 'undefined' || typeof $.ajax == 'undefined') {
var s = document.createElement("script");
s.onload = init;
s.src = "https://cdn.bootcss.com/jquery/3.1.1/jquery.min.js";
document.getElementsByTagName("HEAD")[0].appendChild(s);
} else {
init();
}
//https://timor.tech/api/holiday/year/2024
console.log("holiday_SCRIPT_INIT"); |