|
无刷新鲜花鸡蛋投票代码,不知何故不成功,以下是代码:
ajax.js代码
function v(){
return;
}
//Ajax Start
function Ajax_GetXMLHttpRequest() {
if (window.ActiveXObject) {
return new ActiveXObject("Microsoft.XMLHTTP");
}
else if (window.XMLHttpRequest) {
return new XMLHttpRequest();
}
}
function Ajax_CallBack(ID,URL){
var x = Ajax_GetXMLHttpRequest();
var ID = document.getElementById(ID);
x.onreadystatechange = function(){
if(x.readyState == 4){
if(x.status == 200){
if(x.responseText!=""){
ID.innerHTML=x.responseText;
}else{
alert('您已投过票,不可以重复投票!');}}}}
x.open('GET',URL,true);
x.send(null);
}
//Ajax End
页面代码:
<!--#include File="conn.asp"-->
<script language="javascript" src="ajax.js"></script>
<%set rs=server.CreateObject("adodb.recordset")
sql="select * from news"
rs.open sql,conn,1,1%>
<%n=0
do while not rs.eof%>
<div><a href="javascript:v()" onclick="javascript:Ajax_CallBack('support<%=Rs("id")%>','FlowerEgg.asp?PostID=<%=Rs("id")%>&Status=support')" title="支持一下"><img src="images/1+.gif" width="20" height="20" border="0"></a>[<span id="support<%=Rs("id")%>"><%=rs("flower")%></span>] <a href="javascript:v()" onclick="javascript:Ajax_CallBack('oppose<%=Rs("id")%>','FlowerEgg.asp?PostID=<%=Rs("id")%>&Status=oppose')" title="反对!"><img src="images/1-.gif" width="20" height="20" border="0"></a>[<span id="oppose<%=Rs("id")%>"><%=rs("egg")%></span>]</div>
<%
rs.movenext
n=n+1
if n=10 then exit do
loop
rs.close
%>
FlowerEgg.asp文件代码:
<!--#include file="conn.asp"-->
<%
postID=Request("PostID")
s=Request("status")
if IsNumeric(postID)=true then
Set rs = Server.CreateObject("ADODB.Recordset")
sql = "select * from [news] where ID="&PostID
rs.Open sql,conn,3,2
if instr("|"&Rs("BallotIPList"),"|"&Request.ServerVariables("REMOTE_ADDR")&"|")>0 then
Response.write("")
rs.close
else
if s="support" then
flower=rs("flower")+1
rs("flower")=flower
rs("BallotIPList")=rs("BallotIPList")&Request.ServerVariables("REMOTE_ADDR")&"|"
rs.Update
rs.close
response.write(flower)
response.write""&rs("BallotIPList")&""
elseif s="oppose" then
egg=rs("egg")+1
rs("egg")=egg
rs("BallotIPList")=rs("BallotIPList")&Request.ServerVariables("REMOTE_ADDR")&"|"
rs.Update
rs.close
response.write(egg)
end if
end if
end if
%> |
|