我在游戏操作后触发了以下Javascript代码,以便使用ajax将当前得分保存到数据库:
$(oMain).on("save_score", function(evt,iMoney) {
// alert ('you won: $'+iMoney);
$.ajax({
type: "POST",
url: 'write.php',
data: ({prize:iMoney}),
success: function(data) {
alert(data);
}
});
});
我将write.php文件写入DB:
<?php
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "admin";
$dbname = "games";
$prize=$_POST['prize'];
$query="INSERT INTO game_result (user_, amount)
VALUES('user','$prize')";
$con = new mysqli($dbhost, $dbuser, $dbpass,$dbname);
$qry_result = $con->query($query);
?>
然而,db端没有任何事情发生,ajax返回一个空字符串。我做错了什么?