jquery Ajax No Refresh comment instance

Source: Internet
Author: User
Tags comments trim

<!doctype HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/ Xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<title>jquery Ajax No Refresh comments </title>
<script type= "text/web Effects" src= "jquery. Web Effects" ></script>
<script type= "Text/javascript" >
function Stopbutton () {
document.getElementById (Arguments[0]). Disabled=true;
document.getElementById (Arguments[0]). Value= "Submitted (" +arguments[1]+ ")";
if (--arguments[1]>0) {
Window.settimeout ("Stopbutton" ("+arguments[0]+", "+arguments[1]+") ", 1000);
}
if (arguments[1]<=0) {
document.getElementById (Arguments[0]). value= ' Submit ';
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 (' Please fill in your nickname! ');
$ (' #commentuser '). focus ();
return false;
}
if ($.trim ($commentvalidate) = = ")
{
Alert (' Please fill in the Verification code! ');
$ (' #commentvalidate '). focus ();
return false;
}
if ($.trim ($commenttext) = = ")
{
Alert (' Please fill in the reply content! ');
$ (' #commenttext '). focus ();
return false;
}
if ($commenttext. length<5| | $commenttext. length>200)
{
Alert (' content must be between 5-200 words! ');
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 (' Authentication code Error! ');
}else{
Getcomment ($commentparentid, 0);
Alert (arguments[0]);
$ ("#commenttext"). Val ("");
Refresh the verification code picture when validation succeeds
$ ("#commentvalidateimages"). attr ("src", "code.asp?s=" +math.random ());
}
$ ("#commentvalidate"). Val ("");
}
});
Setcookie ("Commentuser", $commentuser, 3);
}</script>
<link rel= "stylesheet" type= "text/css Course" href= "Style.css"/>
<body>
<div class= "box" >
<div class= "Box-title" > User comments </div>
<div id= "comment" ><!--comments Input box start-->
<div style= "padding:4px" ></div>
<div class= "POST" >
<div style= "padding:4px" ></div>
<label>&nbsp; Johnny &nbsp;&nbsp;&nbsp; said (*) </label> <input type= "text" id= "Commentuser" onfocus= "This.classname= ' Focus postvalidate '" onblur= "This.classname= ' Blur postvalidate '" "class=" Blur Postuser " value= "Anonymous Netizen"/>
<div style= "padding:2px" ></div>
<label>&nbsp; Verification Code (*) </label> <input type= "text" class= "Blur postvalidate" id= "Commentvalidate" onfocus= "This.classname= ' Focus postvalidate '" onblur= "This.classname= ' Blur postvalidate '" "maxlength=" 4 "/>
&nbsp;
<div style= "padding:2px" ></div>
<label>&nbsp; &nbsp;&nbsp;&nbsp; Capacity (*) </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;" >&nbsp;</span><input type= ' button ' class= ' postsubmit ' id= ' commentsubmit ' value= ' Submit ' onclick= ' Sendcomment (1) "/>
<div style= "padding:2px" ></div>
</div>
<!--comments Input box end-->
</div>
<script type= "Text/javascript" >
<! [cdata[
Getcomment (1,1);
]]>
</script>
</body>

<%
<!--#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 as not rs.eof
Temlist = "<div class=" "Comment" ">" &vbcrlf
Temlist = temlist& "<div class=" "Comment-caption" "><span class=" "Comment-user" ">" &rs (0) & "published In </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" "> 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 ("No comment content")
End If
Closers ()
Closeconn ()
' Show page-related information
If Rscount>0 Then
pagehtml = "<div class=" "Pagebar" "> has" &rscount& "article Comments &nbsp; {$link _list$}</div> "
If Pagenum>1 Then
For i = 1 to Pagenum
linkhtml = linkhtml & IIf (i = page, "<span class=" "Current" ">" & I & "</span>&nbsp;", "<a HRE F= "" javascript:void (0) "" onclick= "" Getcomment ("&id&", "&i&") "" > "& I &" </a>& nbsp; ")
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 ("comment published successfully.")
End If
End Function
%>

%>
Article no refresh comment code, if you want to let Ajax load comments and Ajax to send a comment on the download it

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.