我想知道我的逻辑是否正确。我试图在凌晨3点到4点之间调用pullCsv()函数。 moment.js和jquery正在加载到html文件中。
有没有更好的方式来写这个。我对javascript很新,我自己做了。
var csvCache2;
$(document).ready(function () {
chktimeWindow();
});
function chktimeWindow() {
var now = moment();
var evtimeChkA = moment('03:00 AM', 'h:mm A');
var evtimeChkB = moment('04:00 PM', 'h:mm A');
setInterval(function () {
if (now.isAfter(evtimeChkA) && now.isBefore(evtimeChkB)) {
console.log("It's between 3AM and 4PM");
pullCsv();
}
else {
console.log("It's not between 3AM and 4PM");
}
}, 2000);
}
function pullCsv() {
var csvData2;
csvData2 = $.ajax({
type: "GET"
, url: "EVENTS.CSV"
, dataType: "text"
, cache: "false"
, success: function (result) {
csvResult2 = result;
if (csvResult2 == "") {
csvCache = csvResult2;
console.log('NO RESULTS');
}
else {
console.log("RESULTS FOUND");
window.location.assign("index.html?nocache=" + (new Date()).getTime());
}
}
});
};