ASP+ajax實(shí)現(xiàn)頂一下、踩一下同支持與反對(duì)的實(shí)現(xiàn)代碼
1、點(diǎn)擊相應(yīng)頂一下、踩幾下的代碼類似
response.write ("<a href="javascript:void(0)" onclick="digg("&rs("id")&",1)">頂</a>(<span class="ding"&rs("id")&"">"&rs("ding")&"</span>)")
response.write ("<a href="javascript:void(0)" onclick="digg("&rs("id")&",2)">踩</a>(<span class="cai"&rs("id")&"">"&rs("cai")&"</span>)=><a href="article.asp?id="&rs("id")&"">內(nèi)容頁(yè)頂踩</a><br/>")
2、點(diǎn)擊后調(diào)用相應(yīng)的JS函數(shù)ajax傳入相應(yīng)的參數(shù),范例代碼如
function digg(getid,dingcai){ //以.post方式與dingcai.asp文件交互。注意路徑 $.post("inc/dingcai.asp", { "id": getid , "dingcai": dingcai }, function(data){ data=data.indexOf("yang_yes") if(data>=0){ if(dingcai==1){ //重新獲取當(dāng)前"頂"并加1 var ding = parseInt($(".ding"+getid).html())+1; //重新更新"頂"的數(shù)據(jù)入庫(kù) $(".ding"+getid).html(ding); }else{ //踩 var cai = parseInt($(".cai"+getid).html())+1; $(".cai"+getid).html(cai); } alert("感謝你的支持!如果不需要js提示請(qǐng)刪除本行代碼"); }else{ alert("你已經(jīng)投過票了!如果不需要js提示請(qǐng)刪除本行代碼"); } }, "text"); }
3、傳入指定的ASP文件里面實(shí)現(xiàn)范例代碼如
mycookies=0 id = clng(request.form("id")) dingcai = request.form("dingcai") if id<>"" then if request.cookies("mycookies"&id)<>id then "寫入cookies,有效期24小時(shí) Response.cookies("mycookies"&id)=id Response.Cookies("mycookies"&id).expires=dateadd("H",24,now()) else mycookies=1 end if else mycookies=1 end if "接受對(duì)應(yīng)的id "如果頂踩過來的id不為空,并且獲取是頂?shù)牟僮骰虿鹊牟僮?if request.form("id")<>"" and request.form("dingcai")<>"" then "如果是頂?shù)牟僮? 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
這就完成了,列表頁(yè)面與詳情頁(yè)面都可以類似實(shí)現(xiàn)。
大家也可以下載這個(gè)源碼學(xué)習(xí)一下
基于jquery的ajax實(shí)現(xiàn)的網(wǎng)頁(yè)上面的頂一下,踩一下功能代碼,代碼已經(jīng)打包,大家可以看下代碼即可。
到此這篇關(guān)于ASP+ajax實(shí)現(xiàn)頂一下、踩一下同支持與反對(duì)的實(shí)現(xiàn)代碼的文章就介紹到這了,更多相關(guān)ASP 頂、踩、支持與反對(duì)內(nèi)容請(qǐng)搜索以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持!
相關(guān)文章:
1. ASP.NET MVC前臺(tái)動(dòng)態(tài)添加文本框并在后臺(tái)使用FormCollection接收值2. ASP動(dòng)態(tài)網(wǎng)頁(yè)制作技術(shù)經(jīng)驗(yàn)分享3. asp.net core應(yīng)用docke部署到centos7的全過程4. ASP.NET MVC獲取多級(jí)類別組合下的產(chǎn)品5. asp知識(shí)整理筆記2(問答模式)6. asp.net core 認(rèn)證和授權(quán)實(shí)例詳解7. ASP.NET MVC使用jQuery的Load方法加載靜態(tài)頁(yè)面及注意事項(xiàng)8. Asp.Net部署Docker-v指令使用詳解9. asp(vbs)Rs.Open和Conn.Execute的詳解和區(qū)別及&H0001的說明10. ASP.NET MVC使用JSAjaxFileUploader插件實(shí)現(xiàn)單文件上傳
