<!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 select
function 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 function
function 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
%>