asp点赞问题求教
asp吧
全部回复
仅看楼主
level 1
html代码:
<button class="zan">
<i>$article_zan$</i>
</button>
asp代码:
<%
id1=request.querystring("id")
set rs=server.createobject("adodb.recordset")
sql="select [zan],[ip],[id] from [article] where id="&id1&""
rs.open(sql),cn,1,3
if not rs.eof then
rs("zan")=rs("zan")+1
rs.update
end if
rs.close
set rs=nothing
%>
我需要让html的button点击后执行asp里的+1,也就是button去这里( src="/inc/article_zan.asp?id=$article_id$"),怎么能让button到asp页面呢,求教
还有就是我的页面是手动生成静态页的,点赞不能实现实时显示,点赞了要后台生成更新才能显示点赞+1了....有什么方法破吗
2020年12月09日 11点12分 1
吧务
level 14
加油
2020年12月25日 02点12分 2
level 4
用ajax就可以了。javascript来控制。用户点赞后,向后台发送一个请求,把新的点赞数量读取出来,然后送到那个显示数量的容器里面即可。
2021年02月08日 05点02分 3
level 4
html代码:
<button class="zan">
<i onclick="dianzan(this)">$article_zan$</i>
<input id="wzid" type="hidden" value="<%=id%>">
</button>
asp代码:
<%
id1=request.querystring("id")
set rs=server.createobject("adodb.recordset")
sql="select [zan],[ip],[id] from [article] where id="&id1&""
rs.open(sql),cn,1,3
if not rs.eof then
rs("zan")=rs("zan")+1
rs.update
end if
rs.close
set rs=nothing
%>
<script>
var wzid=document.getElementById("wzid");//文章id
function dianzan(obj){
var xmlhttp=new XMLHttpRequest() || new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.open("POST","ajax.asp",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("id="+wzid.value);//发送文章id到后端
xmlhttp.onreadystatechange=function(){//判断后台是否发送数据过来函数
if (xmlhttp.readyState==4 && xmlhttp.status==200){//如果后台有数据发送过来,当然就是点赞量的数据啦。
var node = xmlhttp.responseText;//把后台发送的点赞量赋值给node
obj.innerHTML=node;//把点赞量送入<i></>标签里面去。
}
}
}
</script>
后台接收前端发来的数据
ajax.asp代码:
<!--#include file="conn.asp"-->
<%
id=request("id")
if dianzan="dianzan" then'如果提交过来的数据不是空的
call conn_open(conn,"XXX.mdb")'打开数据库,不知道你的数据库名字,就随便起了个名字xxx.mdb
sql="select zan from [article] where id="&id
call rs_open1(rs,sql)'打开表
if not rs.eof and not rs.bof then'判断是否有数据,如果有数据就...
dz=rs("zan")'把点赞量赋值给dz
end if
call rs_close(rs)'关闭表
call conn_close(conn)'关闭数据库
response.write dz'向前端发送点赞量
end if
%>
2021年02月08日 05点02分 4
1