ASP+ajax實(shí)現(xiàn)頂一下、踩一下同支持與反對的實(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)容頁頂踩</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ù)入庫
$(".ding"+getid).html(ding);
}else{
//踩
var cai = parseInt($(".cai"+getid).html())+1;
$(".cai"+getid).html(cai);
}
alert("感謝你的支持!如果不需要js提示請刪除本行代碼");
}else{
alert("你已經(jīng)投過票了!如果不需要js提示請刪除本行代碼");
}
}, "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
"接受對應(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
這就完成了,列表頁面與詳情頁面都可以類似實(shí)現(xiàn)。
大家也可以下載這個(gè)源碼學(xué)習(xí)一下
基于jquery的ajax實(shí)現(xiàn)的網(wǎng)頁上面的頂一下,踩一下功能代碼,代碼已經(jīng)打包,大家可以看下代碼即可。
到此這篇關(guān)于ASP+ajax實(shí)現(xiàn)頂一下、踩一下同支持與反對的實(shí)現(xiàn)代碼的文章就介紹到這了,更多相關(guān)ASP 頂、踩、支持與反對內(nèi)容請搜索以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持!
相關(guān)文章:
1. ASP.NET MVC使用異步Action的方法2. asp.net core項(xiàng)目授權(quán)流程詳解3. asp中response.write("中文")或者js中文亂碼問題4. ASP腳本組件實(shí)現(xiàn)服務(wù)器重啟5. asp讀取xml文件和記數(shù)6. asp.net core 認(rèn)證和授權(quán)實(shí)例詳解7. AspNetCore&MassTransit Courier實(shí)現(xiàn)分布式事務(wù)的詳細(xì)過程8. 關(guān)于Jenkins + Docker + ASP.NET Core自動(dòng)化部署的問題(避免踩坑)9. ASP中if語句、select 、while循環(huán)的使用方法10. 理解ASP.NET Core 配置系統(tǒng)

網(wǎng)公網(wǎng)安備