ASP jQuery Ajax No Refresh comments

Source: Internet
Author: User

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);
      }
    });
  }
}

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.