通过JS调用ASP,间接对数据库进行操作

  • 内容
  • 评论
  • 相关

刷新静态页面后,数据库的浏览次数也会增加加1~分析代码后把实现这部分功能的代码贴出来,一起分享一下~
test.html

程序代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="UTF-8">
<head>
<base href="http://192.168.1.199:100/ymx/"></base>
<script type="text/javascript">
//Author:PuterJam
function $()
{
    var elements = new Array();
    for (var i = 0; i < arguments.length; i++)
    {
        var element = arguments[i];
        if (typeof element == 'string')
            element = document.getElementById(element);
        if (element) {
        } else {
            element = null;
        }
        if (arguments.length == 1) {
            return element;
        } else {
            elements.push(element);
        }
    }
    return elements;
}
//计数器
function ping(){
    setTimeout(toPing,500);
}

//开始统计
function toPing(){
    var pingBlog = document.createElement("script");
    pingBlog.chatset = "utf-8";
    pingBlog.src = "test.asp?id=1";
    
    document.getElementsByTagName("HEAD")[0].appendChild(pingBlog);
}

//ping的回调
function callPing(num){
    $("countNum").innerHTML = num;
}
</script>
</head>
<body>
查看次数: <span id="countNum">-</span>
</body>
</html>
  </div>
</div>
<script type="text/javascript">
    ping();
</script>
</body>
</html>

调用数据库实现浏览次数+1,并显示浏览次数

 

程序代码
'////连接数据库代码省略了哈~
<%
Response.CacheControl = "no-cache"
sql="select * from test where id=1"
rs.open sql,conn,1,3
if not rs.eof then
    num=rs("pagenum")+1
    rs("pagenum")=num
    rs.update    
end if
rs.close
set rs=nothing
outputPing num
%>
<script runat="server" Language="javascript">
    function outputPing(num){
        Response.Write ("callPing('" + num + "');")
    }
</script>

评论

0条评论

    发表评论

    电子邮件地址不会被公开。 必填项已用*标注

    click to change 看不清?点击换一张!