<!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">
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title>jquery ajax无刷新评论</title>
<script type="text/网页特效" src="jquery.网页特效"></script>
<script type="text/javascript" >
function stopbutton(){
document.getelementbyid(arguments[0]).disabled=true;
document.getelementbyid(arguments[0]).value="提交("+arguments[1]+")";
if(--arguments[1]>0){
window.settimeout("stopbutton('"+arguments[0]+"',"+arguments[1]+")",1000);
}
if(arguments[1]<=0){
document.getelementbyid(arguments[0]).value='提交';
document.getelementbyid(arguments[0]).disabled=false;
}
}
function getcomment($id,$page){
$.ajax({
url:"comment.asp?action=ajax_getcomment&id="+$id+"&page="+$page+"&time"+new date().tostring(),
type:'get',
success:function(){
$('#comment').html(arguments[0]);
}
});
}
function sendcomment(){
var $commentparentid =arguments[0];
var $commentuser =$('#commentuser').val();
var $commenttext =$('#commenttext').val();
var $commentvalidate =$('#commentvalidate').val();
if ($.trim($commentuser)=='')
{
alert('请您填写昵称!');
$('#commentuser').focus();
return false;
}
if ($.trim($commentvalidate)=='')
{
alert('请您填写验证码!');
$('#commentvalidate').focus();
return false;
}
if ($.trim($commenttext)=='')
{
alert('请您填写回复内容!');
$('#commenttext').focus();
return false;
}
if ($commenttext.length<5||$commenttext.length>200)
{
alert('内容必须在5-200字之间!');
return false;
}
stopbutton('commentsubmit',10);
$.ajax({
url:"comment.asp?action=ajax_sendcomment&commentparentid="+$commentparentid+"&commentuser="+escape($commentuser)+"&commenttext="+escape($commenttext)+"&commentvalidate="+escape($commentvalidate)+"&time="+new date().tostring(),
type:'get',
success:function(){
if (arguments[0]=='error')
{
alert('验证码出错!');
}else{
getcomment($commentparentid,0);
alert(arguments[0]);
$("#commenttext").val("");
//验证成功时,刷新验证码图片
$("#commentvalidateimages").attr("src","code.asp?s="+math.random());
}
$("#commentvalidate").val("");
}
});
//setcookie("commentuser",$commentuser,3);
}</script>
<link rel="stylesheet" type="text/css教程" href="style.css" />
</head>
<body>
<div class="box">
<div class="box-title">网友评论</div>
<div id="comment"><img src="wait.gif" title="数据载入中..." /></div>
<!--评论输入框开始-->
<div style="padding:4px"></div>
<div class="post">
<div style="padding:4px"></div>
<label> 昵 称(*)</label> <input type="text" id="commentuser" onfocus="this.classname='focus postvalidate'" onblur="this.classname='blur postvalidate'" class="blur postuser" value="匿名网友" />
<div style="padding:2px"></div>
<label> 验证码(*)</label> <input type="text" class="blur postvalidate" id="commentvalidate" onfocus="this.classname='focus postvalidate'" onblur="this.classname='blur postvalidate'" maxlength="4" />
<img id='commentvalidateimages' style='cursor:pointer;height:20px;width:80px;' src="about:blank" onerror="this.onerror=null;this.src='code.asp?s='+math.random();" alt="验证码" title="看不清楚?换一张" onclick="src='code.asp?s='+math.random()" />
<div style="padding:2px"></div>
<label> 内 容(*)</label> <textarea id="commenttext" onfocus="this.classname='focus posttext'" onblur="this.classname='blur posttext'" class="blur posttext"></textarea>
<div style="padding:2px"></div>
<span style="padding-left:60px;"> </span><input type='button' class="postsubmit" id="commentsubmit" value='提交' onclick="sendcomment(1)" />
<div style="padding:2px"></div>
</div>
<!--评论输入框结束-->
</div>
<script type="text/javascript">
//<![cdata[
getcomment(1,1);
//]]>
</script>
</body>
</html><%
<!--#include file="c.asp"-->
<%
dim action, id, page, pagehtml, pages, linkhtml
pages = 5
action = request.querystring("action")
id = request.querystring("id")
page = request.querystring("page")
select case action
case "ajax_getcomment"
ajax_getcomment()
case "ajax_sendcomment"
ajax_sendcomment()
case else
echo("erro")
end selectfunction ajax_getcomment()
dim temlist, getlist
openconn(dbpath)
sql = "select commentuser,commentdate,commenttext,commentreply from comment where commentparentid="&id&" order by commentid asc"
call openrs(sql, 1)
if not(rs.bof and rs.eof) then
rs.pagesize = pages
rscount = rs.recordcount
pagenum = rs.pagecount
page = clng(page)
if page < 1 then page = 1
if page > pagenum then page = pagenum
rs.absolutepage = page
k = 1
do while not rs.eof
temlist = " <div class=""comment"">"&vbcrlf
temlist = temlist& " <div class=""comment-caption""><span class=""comment-user"">"&rs(0)&" 发表于 </span> <span class=""comment-date"">"&rs(1)&"</span></div>"&vbcrlf
temlist = temlist& " <div class=""comment-text"">"&rs(2)&"</div>"&vbcrlf
if rs(3)<>"" then
temlist = temlist& " <div class=""comment-reply"">回复:"&rs(3)&"</div>"&vbcrlf
end if
temlist = temlist& " </div>"&vbcrlf
k = k + 1
rs.movenext
getlist = getlist & temlist
if k > pages then exit do
loop
else
echo ("暂无评论内容")
end if
closers()
closeconn()
'显示分页相关信息
if rscount>0 then
pagehtml = "<div class=""pagebar"">已有"&rscount&"条评论 {$link_list$}</div>"
if pagenum>1 then
for i = 1 to pagenum
linkhtml = linkhtml & iif(i = page, "<span class=""current"">"& i &"</span> ", "<a href=""javascript:void(0)"" onclick=""getcomment("&id&","&i&")"">" & i & "</a> ")
next
else
linkhtml = ""
end if
pagehtml = replace(pagehtml, "{$link_list$}", linkhtml)
end if
echo (getlist&pagehtml)
end functionfunction ajax_sendcomment()
dim commentparentid, commentuser, commenttext, commentvalidate
openconn(dbpath)
commentparentid = request.querystring("commentparentid")
commentuser = unescape(request.querystring("commentuser"))
commenttext = unescape(request.querystring("commenttext"))
commentvalidate = unescape(request.querystring("commentvalidate"))
if cstr(session("getcode"))<>commentvalidate then
echo ("error")
response.end()
else
sql = "insert into comment(commentparentid,commentuser,commenttext,commentreply,commentip) values('"&commentparentid&"','"&commentuser&"','"&server.htmlencode(commenttext)&"','','"&getip()&"')"
set rs = conn.execute(sql)
closers()
closeconn()
echo ("评论发表成功.")
end if
end function
%>
%>
文章无刷新评论代码,如果你想让ajax加载评与ajax发送评论话就下载吧