【发布时间】:2016-02-15 16:06:01
【问题描述】:
我正在尝试提交表单而不刷新页面。我的 php 代码如下所示:
<form>
<label for="roundcheck" style="color: red; font-size: 16pt;font-family: roboto;">Round: </label>
<input type="text" name="roundcheck" class="textbox" style="" id="roundcheck" value="<?php $game = fetchinfo("value","info","name","current_game"); echo $game-1; ?>" placeholder="Round number">
<input type="submit" id="checkbtn" class="button2" value="Check">
</form>
<div id="checkinfo">
</div>
$(document).ready(function(){
$('#checkbtn').click(function() {
$("#checkinfo").show("fast");
$.ajax({
type: "GET",
url: "checkfair.php",
}).done(function (msg) {
msg = $.trim(msg);
if (msg != '[]') {
var obj = jQuery.parseJSON(msg);
$("#checkinfo").html=('<p>Round <span style="color:red;">#'+obj.round+'</span><br>Value: <span style="color:red;">$'+obj.value+'</span><br>Winner: <span style="color:red;">'+obj.winner+'</span><br>Hash: <span style="color:red;">'+obj.hash+'</span><br>Salt: <span style="color:red;">'+obj.salt+'</span><br>Ticket: <span style="color:red;">'+obj.ticket+'</span></p>');
}
});
});
});
<?php
@include_once ("set.php");
$round = $_GET["roundcheck"];
echo json_encode([
"round" => $round,
"value" => round(fetchinfo("cost", "games", "id", $round), 2),
"winner" => fetchinfo("winner", "games", "id", $round),
"hash" => fetchinfo("hash", "games", "id", $round),
"salt" => fetchinfo("salt", "games", "id", $round),
"ticket" => round(fetchinfo("winticket", "games", "id", $round) * 100, 7)
]);
?>
当我按下“checkbtn”而不刷新表单时,我希望所有内容都显示在<div id="checkinfo">。
【问题讨论】:
-
你有什么问题?
标签: javascript php jquery html ajax