注意:在发布之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。
- Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5或Ctrl-R(Mac为⌘-R)
- Google Chrome:按Ctrl-Shift-R(Mac为⌘-Shift-R)
- Internet Explorer或Edge:按住Ctrl的同时单击刷新,或按Ctrl-F5
- Opera:按 Ctrl-F5。
/* 这里的任何JavaScript将为所有用户在每次页面载入时加载。 */
$(function() {
if ($("#live-player-status").length > 0) {
$.ajax({
type: "GET",
url: "https://he-api.hydcraft.cn/",
dataType: "jsonp",
jsonp: "callback",
success: function (data) {
var curPlayers = data.current_players;
var maxPlayers = data.max_players;
var width = curPlayers / maxPlayers;
var statusText = "服务器在线人数" + data.current_players + " / " + data.max_players;
$("#live-player-status").html(statusText);
$("#live-player-progress").width(width + '%');
},
error: function (xhr) {
if (xhr.status == 502) {
$("#live-player-status").html("服务端未启动。");
} else {
$("#live-player-status").html("无法获取信息,错误值:" + xhr.status + "。");
$("#live-player-progress").width(100 + '%');
$("#live-player-progress").css("background-color" , "#ff0000");
}
}
});
}
}());