自做asp与AJAX之投票系统
来源:互联网 发布:windows在哪下载 编辑:程序博客网 时间:2024/05/01 09:22
自做AJAX之投票系统
(自学真难,写出来也难。题外话^_^),第一次写的东西,不太好,过路高手指点啦。
自做AJAX之投票系统,无刷新调取其它页面数据。
JavaScript语言,.js文件内容:
var xmlHttp = false; //
//初始化XMLHttpRequest对象
function createXmlHttp(){
xmlHttp = false;
if (window.ActiveXObject) {
try {xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");}
catch (e) {xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");}
}else if (window.XMLHttpRequest) {xmlHttp = new XMLHttpRequest();}
}
function sendRequest(idnum,strType){
createXmlHttp();
var url = "toupiao.asp?downId=" + idnum + "&piaoType=" + strType+"×tamp=" + new Date().getTime();
if (!xmlHttp) {
alert("XMLHttpRequest 创建失败!");
}
xmlHttp.open("GET", url, false);
xmlHttp.onreadystatechange = function(){//回调函数开始
var goodimg,goods,badimg,bads;
goodimg = document.getElementById("goodimg");
goods=document.getElementById("goodSpan");
badimg = document.getElementById("badimg");
bads=document.getElementById("badSpan");
//alert(xmlHttp.responseText);
if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
var requTxt= xmlHttp.responseText;
if (requTxt=="true")
{
alert("你已投过票!请20分钟之后再继续。");
}else{
var splitTxt=requTxt.split("###");
var pa=parseInt(splitTxt[0]);
var pb=parseInt(splitTxt[1]);
var requTxt=pa + pb;
var num=((pa/requTxt)*100)/2;
var num1;
if (Math.round(num)==0 || Math.round(num)=="")
{
num1="0";
}else num1=Math.round(num);
var num2=num1 + "." + shudian(num) + " %";
goodimg.style.width=num1;
goods.innerText=num2;
num=((pb/requTxt)*100)/2;
if (Math.round(num)==0 || Math.round(num)=="")
{
num1="0";
}else num1=Math.round(num);
num2=num1 + "." + shudian(num) + " %";
badimg.style.width=num1;
bads.innerText=num2;
alert("投票成功!");
}
//alert(num2);
}
}//回调函数结束
xmlHttp.send(null);
}
function shudian(a){//取小数点后2位
var i=a.toString().indexOf(".");
var a1=a.toString().substring(i+1,i+3);
return a1;
}
ASP数据文件内容:
<%
Dim rs,db,conn,str
conn=server.mappath("database/shangpin.mdb")
set db=server.createobject("adodb.connection")
db.open "driver={microsoft access driver (*.mdb)};dbq="&conn
Set rs=server.CreateObject("adodb.recordset")
If Err Then
Err.clear
response.write "数据库链接错误,请查询数据库链接语句。"
Call dbclose()
response.End
End If
Function dbclose()
Set rs=Nothing
db.close
Set db=Nothing
End function
Dim downId,piaoType
downId=Trim(request("downId"))
piaoType=Trim(request("piaoType"))
´downId=6
´piaoType="good"
If downId<>"" And IsNumeric(downId) Then
str="select shang_piao_ip,shang_piao_date from shangpin where id="&downId
rs.open str,db
Dim shangIp,shangDate,piaoId
If Not rs.eof Or Not rs.bof Then
shangIp=rs("shang_piao_ip")
shangDate=rs("shang_piao_date")
End If
rs.close
Dim ip
ip=request.serverVariables("REMOTE_ADDR")
If ip=shangIp And DateDiff("n",shangDate,Now())<20 Then
response.write "true"
Else
If piaoType<>"" Then
If piaoType="good" Then
str="update shangpin set shang_piao_good=shang_piao_good+1,shang_piao_ip=´"& request.serverVariables("REMOTE_ADDR") &"´,shang_piao_date=´"& Now() &"´ where id="&downId
db.execute(str)
str="select * from shangpin where id="&downId
rs.open str,db
response.write CStr(rs("shang_piao_good")) & "###" & CStr(rs("shang_piao_bad"))
rs.close
Set rs=Nothing
db.close
Set db=Nothing
Else
str="update shangpin set shang_piao_bad=shang_piao_bad+1,shang_piao_ip=´"& request.serverVariables("REMOTE_ADDR") &"´,shang_piao_date=´"& Now() &"´ where id="&downId
db.execute(str)
str="select * from shangpin where id="&downId
rs.open str,db
response.write CStr(rs("shang_piao_good")) & "###" & CStr(rs("shang_piao_bad"))
rs.close
Set rs=Nothing
db.close
Set db=Nothing
End If
End If
End If
End If
%>
- 自做asp与AJAX之投票系统
- 用ASP编写网上调查投票系统(转自赛迪网)
- php和Ajax 投票系统
- 投票系统(Flash+ASP案例)
- 投票系统之防止重复投票
- 静中有动,ajax之投票感受
- 用flash做的投票系统
- PHP做的一个简单投票系统
- php模块之投票系统
- 结构体之投票系统
- C# asp.net与jquery做ajax简单进度条
- 投票系统投票界面
- 投票系统的设计与实现
- Zend framework 之投票系统流程图
- Django快速开发之投票系统
- JSP MVC模式案例之投票系统
- 投票系统
- 投票系统
- Delphi7下安装Ehlib 4.3
- Talk:OpenGL GUI Framework
- 感悟javascript(我的学习历程)
- What GUI system to use for C++/Ogre MMOG?
- 在WPF里面获取右键弹出菜单(ContextMenu)的鼠标点击源(Owner)控件
- 自做asp与AJAX之投票系统
- 堆和栈的区别
- DELPHI+MSSQL工业控制之数据采集系统(毕业论文+文献综述+外文翻译+可执行程序+源代码)
- 使用CAST来SQL注入
- Flex中 encodeURI 对url进行编码,中文url
- 还是,Stairway To Haven
- 练手小项目(二):计算器(说明文档)
- 练手小项目(二)计算器
- Linux新手要了解的十个知识点