【发布时间】:2014-01-04 20:59:47
【问题描述】:
我有以下脚本,它根据数据库结果显示图像。当用户单击图像时,它会更改为新图像。 green_star 表示$user_id 和$thedb_id 存在于数据库中,grey_star 表示它们不存在。我正在寻找的是一种在单击星号时插入或从数据库中删除的方法。在 PHP 中我知道我会这样做
INCLUDE 'addTo_watchlist.php?user_id=$user_id&thetvdb_id=$thetvdb_id';
但 JavaScript 不接受该格式的发布数据。是否可以做我正在寻找的事情,如果可以,最好的路线是什么?
<script type="text/javascript">
function changeIt(id)
{
var theImg = document.getElementById(id),
x = theImg.src.split("/"),
t = x.length-1,
y = x[t];
if(y == 'grey_star.gif')
{
theImg.src='./images/green_star.gif'
}
if(y == 'green_star.gif')
{
theImg.src='./images/grey_star.gif'
}
}
</script>
<a onclick="changeIt('<?php echo $img_id; ?>')"><img src='<?php echo $image; ?>' name='<?php echo $img_id; ?>' id='<?php echo $img_id; ?>' border='0' width='50%' /></a>
【问题讨论】:
标签: javascript php post