它没有更新,我错过了我做错了什么。使用 HTML、jQuery 和 PHP。所有代码都发布在下面。
我正在尝试做的是允许用户更改“客户端”种子,并且当它更改时它会更新。在它显示。所做的只是每 100 毫秒从一个回显它的文件刷新一次。那里没有问题。
PHP代码:
<?php
session_start();
include_once('db.php');
if(isset($_POST['action'])) {
switch($_POST['action']) {
case 'get_client':
echo json_encode(array('result' => $_SESSION['client']));
break;
case 'modify_client':
if(isset($_POST['client']) && strlen($_POST['client']) == 6 && is_numeric($_POST['client'])) {
$_SESSION['client'] = $_POST['client'];
echo json_encode(array('result' => true));
$secret = 123;
$_SESSION['server'] = hash('sha512', $_SESSION['roll'] . $_SESSION['client'] . $secret );
}
else {
echo json_encode(array('result' => false));
}
break;
}
}
?>
Javascript/jQuery:
<script type="text/javascript">
$.post('./php/show_client.php', { action: 'get_client' }, function(result) {
var result = JSON.parse(result);
})
});
$("#client_seed_modify").on("click", function() {
$.post('./php/show_client.php', { action: 'modify_client', client: $("#client_seed").val() }, function(result) {
var result = JSON.parse(result);
if(result ) {
if(result.result) {
alert('Your Client Seed has been changed. This has also changed the server seed. Please note that you have the ability to change your client seed freely, but regardless of whether or not you decide to, it does NOT stay the same every roll.');
}
}
});
</script>
HTML:
<a>Current Client Seed: <span class="clientShow" style=""> </span></a>
<p class="field">
<input type="text" placeholder="Change your Client Seed" name="client" id="cient_seed" class="client_seed">
</p>
<p class="field">
<input type="submit" value="Change Client Seed" style="width: 360px;" name="client_seed_modify" id="client_seed_modify">
</p>