问题描述
您好,
我正在尝试创建一个收藏夹而不是最喜欢的按钮。
沉闷的明星 - 不喜欢
明星 - 最喜欢的
因此,当点击暗淡的星星时,数据库会更新,并显示一个明亮的星星,现在点击亮星,数据库会更新并出现暗淡的星星。
我使用以下代码 -
< pre lang =的Javascript>
< script type =text / javascript>
函数最爱()
{
var xmlhttp;
var js_aid =<?php echo $ aid;?>;
var js_user =<?php echo $ user;?>;
if(window.XMLHttpRequest)
{//代码用于IE7 +,Firefox,Chrome,Opera,Safari
xmlhttp = new XMLHttpRequest();
}
else
{// IE6的代码,IE5
xmlhttp = new ActiveXObject(Microsoft.XMLHTTP);
}
xmlhttp.onreadystatechange = function()
{
if(xmlhttp.readyState == 4&& xmlhttp.status == 200)
{
document.getElementById(myDiv)。innerHTML = xmlhttp.responseText;
document.getElementById(mybutton)。style.display ='none';
}
}
xmlhttp.open(GET,http://test.xyz.php?aid =+ js_aid +& user =+ js_user,TRUE);
xmlhttp.send();
}
在xyz.php页面中,我添加了sql查询来更新记录和显示暗淡的星。现在我不明白的是我应该在哪里添加不喜欢的功能,以便它全部异步发生..
谢谢
Hello,
I am trying to create a favorite and not favorite button.
A dull star - not favorite
A bright star - Favorite
So on clicking a dull star, database is updated and a bright star is displayed and now on clicking bright star, database is updated and dull star appears.
I am using following code -
<pre lang="Javascript"> <script type="text/javascript"> function favourite() { var xmlhttp; var js_aid = "<?php echo $aid; ?>"; var js_user = "<?php echo $user; ?>"; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("myDiv").innerHTML=xmlhttp.responseText; document.getElementById("mybutton").style.display ='none'; } } xmlhttp.open("GET","http://test.xyz.php?aid="+ js_aid + "&user=" + js_user,true); xmlhttp.send(); }
In xyz.php page I have added sql query to update the records and the display dull star. Now what I don't understand is where should i add notfavorite function so that it all happens asynchronously..
Thanks
这篇关于单击并更新数据库时切换图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!