小无编辑摘要 |
小无编辑摘要 |
||
| 第15行: | 第15行: | ||
}); | }); | ||
if (delayedNames.length > 0) { | if (delayedNames.length > 0) { | ||
$("#live-delay-info").html("<b style='color:red'> | $("#live-delay-info").html("服务器运行中。<b style='color:red'>有线路发生阻塞:" + delayedNames.join("、") + "。</b>"); | ||
} else { | } else { | ||
$("#live-delay-info").html(" | $("#live-delay-info").html("服务器运行中。所有线路运行正常。"); | ||
} | } | ||
}) | }) | ||
.fail(function (xhr, textStatus) { | .fail(function (xhr, textStatus) { | ||
$("#live-delay-info").html("<b style='color:red'> | if (xhr.status == 502) { | ||
$("#live-delay-info").html("服务器当前未启动,或处于休眠状态。"); | |||
} else { | |||
$("#live-delay-info").html("<b style='color:red'>获取信息失败: " + xhr.status + " " + textStatus + "。</b>"); | |||
} | |||
}); | }); | ||
} | } | ||
}()); | }()); | ||
2022年6月2日 (四) 08:22的版本
/* 这里的任何JavaScript将为所有用户在每次页面载入时加载。 */
$(function() {
if ($("#live-delay-info").length > 0) {
$.getJSON("/mtrmap/data")
.done(function (data) {
var delayedNames = [];
data[0].routes.forEach(function(route) {
if (route.maxWaitTime > 2400) {
var routeName = route.name.split("|")[0];
if (delayedNames.indexOf(routeName) < 0) {
delayedNames.push(routeName);
}
}
});
if (delayedNames.length > 0) {
$("#live-delay-info").html("服务器运行中。<b style='color:red'>有线路发生阻塞:" + delayedNames.join("、") + "。</b>");
} else {
$("#live-delay-info").html("服务器运行中。所有线路运行正常。");
}
})
.fail(function (xhr, textStatus) {
if (xhr.status == 502) {
$("#live-delay-info").html("服务器当前未启动,或处于休眠状态。");
} else {
$("#live-delay-info").html("<b style='color:red'>获取信息失败: " + xhr.status + " " + textStatus + "。</b>");
}
});
}
}());