Do a company website when an application, with the Cat East form verification plug-in to do real-time verification, and jquery Ajax submission data, get comments when adding simple pagination
The principle is very simple, pay attention to the coding problem on the line
Achieve access to the comments no refresh, published comments No refresh, page get comments when the display loading load effect
jquery is really a very good JS library, simple and easy to master, for the Web page in the multi-level menu, cascading Effect, tab tab switch, picture rotation display, realize all very simple, often is a few code.
To do AJAX applications, jquery provides $.get (), $.post () functions can be used to submit data, but it is recommended to use $.ajax () to submit, neither of the functions provide error return information, the negative overall control.
See Code implementation, here I cut a part for easy explanation (comments.asp):
$(function(){
//页面初始化时获取评论内容
getComments(1);
});
//获取评论内容
function getComments(pageno){
$.ajax({
type:"GET",
url:"proc_comments.asp",
data:"action=getComments&id=44&page="+pageno+"&num="+Math.round(Math.random()*10000),
error:function(){$("#comm_list table tr td").html("获取评论信息失败");},
success:function(comments_data){
$("#comm_list").html(comments_data);
}
});
}
Add comments to the database, while updating the display, note escape encoding after submitting
function addComments(){
if($.formValidator.pageIsValid()){
$.ajax({
type:"POST",
url:"proc_comments.asp",
data:"action=addcomments&id=44&comm_user="+escape($("#comm_user").val())+"&comm_content="+escape($("#comm_content").val()),
success:function(){
getComments(1);
}
});
}
}