ASP+ajax实现顶一下、踩一下同支持与反对的实现代码(ajax刷新整个页面)怎么可以错过

随心笔谈9个月前更新 admin
196 00
🌐 经济型:买域名、轻量云服务器、用途:游戏 网站等 《腾讯云》特点:特价机便宜 适合初学者用 点我优惠购买
🚀 拓展型:买域名、轻量云服务器、用途:游戏 网站等 《阿里云》特点:中档服务器便宜 域名备案事多 点我优惠购买
🛡️ 稳定型:买域名、轻量云服务器、用途:游戏 网站等 《西部数码》 特点:比上两家略贵但是稳定性超好事也少 点我优惠购买

文章摘要

这篇文章主要介绍了如何使用 cookies 和数据库来管理用户的踩踏记录。代码中定义了变量 `mycookies` 用于记录用户是否已有踩踏记录,`id` 用于唯一识别每个踩踏操作。文章描述了前端如何从 `request` 对象中获取 `id` 和 `dingcai`(踩踏类型),并通过 cookies 判断用户是否已有记录。当用户提交有效的 `id` 和 `dingcai` 时,前端会更新数据库中的记录,并根据记录是否存在将结果写入 cookie 中。此外,文章提到 `mycookies` 的默认值为 0,表示用户首次操作时将被视为未有记录。代码还设置了 cookie 的有效性时间为24小时,确保记录在有效期内。


mycookies=0
id=clng(request.form(“id”))
dingcai=request.form(“dingcai”)
if id<>”” then
if request.cookies(“mycookies”&id)<>id then
‘写入cookies,有效期24小时
Response.cookies(“mycookies”&id)=id
Response.Cookies(“mycookies”&id).expires=dateadd(“H”,24,now())
else
mycookies=1
end if
else
mycookies=1
end if

‘接受对应的id
‘如果顶踩过来的id不为空,并且获取是顶的操作或踩的操作
if request.form(“id”)<>”” and request.form(“dingcai”)<>”” then

‘如果是顶的操作
if dingcai=1 then
sql=”update dingcai set ding=ding+1 where id=”&id
else
sql=”update dingcai set cai=cai+1 where id=”&id
end if

if mycookies=0 then
conn.execute(sql)
response.write “yang_yes”
else
response.write “yang_no”
end if
end if

© 版权声明

相关文章