我有问题。
成功或错误后,该代码应在现场更改图像:
if(isset($func) and $func == 'claim_bonus'){
global $ado;
$user = escape($_GET['user']);
$type = escape($_GET['type']);
$now = date("Y-m-d H:i:s");
$points = rand(1,20);
$query = $ado->exec("INSERT INTO `claimed_bonuses` SET `user` = '$user', `date` = '$now', `type` = '$type'");
$query1 = $ado->exec("INSERT INTO `history` SET `user` = '$user', `date` = '$now', `type` = 'bonus', `amount` = '$points', `title` = 'Bonus Claimed', `description` = '$user claimed bonus $points points'");
$query2 = $ado->exec("update `balances` SET `actual` = actual+$points, `total` = total+$points");
if ($query && $query1 && $query2) {
echo "<img src=\"/img/bonus/add_used.png\" width=\"30%\" height=\"30%\" alt=\"Bonus claimed\" />";
} else {
echo "<img src=\"/img/bonus/error.png\" width=\"30%\" height=\"30%\" alt=\"Error\" />";
}
}
我使用ajax.js 文件调用 ajax
// JavaScript Document
var xmlhttp=false;
function claimbonus(user, type, id){
xmlhttp = new XMLHttpRequest();
xmlhttp.abort();
xmlhttp.open("GET", "/functions/ajax.php?func=claim_bonus&user="+user+"&type="+type, true);
xmlhttp.onreadystatechange=function() {
if(xmlhttp.status == 200) {
document.getElementById(id).innerHTML = xmlhttp.responseText;
}
}
xmlhttp.send(null);
}
代码在页面上加载。
脚本正在返回图像,但它不会替换旧图像。
图片代码:
<img src="img/bonus/add.png" width="30%" height="30%" alt="Claim bonus" id="add_img" onclick="claimbonus(<?php echo $_SESSION['userid']; ?>, '<?php echo $type; ?>', 'add_img'); return false"/>
我希望有一个人可以帮助我