script type=textjavascript var card = getCookiecard; 获取 cookie 中的卡密 if card == null 如果没有 cookie windowlocationhref = kamiphp; 跳转到 kamiphp 页面 else 如果有 cookie updateCardcar
<html>
<body>
<button onclick="getRemainingTime()">查询剩余时间</button>
<div id="remaining-time"></div>
<!-- 其他 HTML 内容 -->
<script type="text/javascript">
// 点击按钮后,查询卡密剩余使用时间
function getRemainingTime() {
var card = getCookie("card"); // 获取 cookie 中的卡密
var xhr = new XMLHttpRequest();
xhr.open("GET", "time.php?card=" + card, true);
xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.DONE) {
if (xhr.status === 200) {
document.getElementById("remaining-time").textContent =
"卡密剩余使用时间:" + xhr.responseText;
} else {
console.log("Error: " + xhr.status);
}
}
};
xhr.send();
}
// 更新指定卡密的使用状态
function updateCard(card, callback) {
const xhr = new XMLHttpRequest();
xhr.open("POST", "update.php");
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.DONE) {
if (xhr.status === 200) {
if (xhr.responseText === "success") {
callback(true);
} else {
callback(false);
}
} else {
console.log("Error: " + xhr.status);
}
}
};
xhr.send("card=" + card);
}
// 获取指定名称的 cookie 值
function getCookie(name) {
var value = "; " + document.cookie;
var parts = value.split("; " + name + "=");
if (parts.length == 2) {
return parts.pop().split(";").shift();
}
}
</script>
</body>
</html>
原文地址: http://www.cveoy.top/t/topic/6o6 著作权归作者所有。请勿转载和采集!