我正在建立一个用户提交问题答案的网站,然后在其$_SESSION
和$_COOKIE
变量上添加一个点,问题是在手动刷新之前它不会更新这页纸。我应该怎么解决这个问题?
代码:
<?php
if(!isset($_COOKIE['score']) AND !isset($_COOKIE['scoreright'])) {
setcookie("score", 0, strtotime( '+1 year' ), "/");
setcookie("scoreright", 0, strtotime( '+1 year' ), "/");
}
$cscore = $_COOKIE['score'];
$cscoreright = $_COOKIE['scoreright'];
session_start();
if(!isset($_SESSION['scoreright']) AND !isset($_SESSION['score'])) {
$_SESSION['score'] = 0;
$_SESSION['scoreright'] = 0;
}
if(isset($_POST['check']) AND isset( $_POST['ODP'])) {
if($_POST['ODP'] == $_POST['POPODP']) {
++$cscore;
++$cscoreright;
setcookie("score", $cscore, strtotime( '+1 year' ), "/");
setcookie("scoreright", $cscoreright, strtotime( '+1 year' ), "/");
$_SESSION['score']++;
$_SESSION['scoreright']++;
//echo "Poprawna odpowiedź";
} else {
//echo "Zła odpowiedź";
++$cscore;
setcookie("score", $cscore, strtotime( '+1 year' ), "/");
$_SESSION['score']++;
}
}
?>
代码:
<script type="text/javascript">
$(".submit").click(function() {
var odp = $('input[name=ODP]:checked').val();
var popodp = $('input[name=POPODP]').val();
var ch = true;
$.ajax({
type: "POST",
url: "includes/points.php",
data: { ODP:odp, POPODP: popodp, check: ch },
success: function(result){
toastr["success"]("Poprawna odpowiedź.");
}
});
});
</script>
代码:
<div class="question">Question</div>
<input type="radio" id="odp1" value="1" name="ODP" hidden>
<label for="odp1">2</label>
<input type="radio" id="odp2" value="2" name="ODP" hidden>
<label for="odp2">1</label>
<input type="radio" id="odp3" value="3" name="ODP" hidden>
<label for="odp3">3</label>
<input type="radio" id="odp4" value="4" name="ODP" hidden>
<label for="odp4">4</label>
<input type="text" value="2" name="POPODP" hidden>
<input class="btn submit" type="submit" name="check" value="ODPOWIADAM">
代码:
<div class="session-cookie">
<div class="stats">
<b>Odpowiedzi ogółem:</b>
<span style="color:#64B5F6">odpowiedzi </span><b><?php echo $cscore; ?></b>,
<span style="color:#81C784;">poprawnych</span> <b><?php echo $cscoreright;?></b> i <span style="color:#E57373;">niepoprawnych</span> <?php echo $cscore - $cscoreright;?>.
</div>
<div class="stats">
<b>W tej sesji:</b>
<span style="color:#64B5F6">odpowiedzi </span><b><?php echo $_SESSION['score']; ?></b>,
<span style="color:#81C784;">poprawnych</span> <b><?php echo $_SESSION['scoreright'];?></b> i <span style="color:#E57373;">niepoprawnych</span> <?php echo $_SESSION['score'] - $_SESSION['scoreright'];?>.
</div>
</div>
我感谢任何帮助。提前谢谢。
//Odpowiedź=答案,Zła= Bad,Poprawna =好,ODPOWIADAM =我回答,niepoprawnych = Bad Answers(在此意义上)。