Ajax Blog Several functions used in the 1th/3 page _javascript Tips

Source: Internet
Author: User
Tags gettext
class Name: AJAX
Copy Code code as follows:

/* Class Name: AJAX

Create method: var ajaxobj=new AJAX; returns false if the creation fails

Properties: Method-Request methods, strings, post or get, default to post
URL-Request URL, string, default is NULL
Async-Asynchronous, true to asynchronous, false to synchronous, default to True
Content-the contents of the request, if this attribute is set by the request method for post, the default is null
Backtext-Default True returns Xmlhttp.responsexml when Xmlhttp.responsetext is False when Backtext=true is returned
GetText-Return value
Callback-callback function, that is, the function called when the response content is returned, the default is direct return, and the callback function has a parameter of XMLHttpRequest object, that is, when defining a callback function: function Mycallback (xmlobj)

Method: Send ()-Sending request, no parameters

*/

function AJAX () {
var XMLHttp = false;
var objself;
Objself=this;
try {xmlhttp=new XMLHttpRequest;}
catch (e) {
try {xmlhttp=new ActiveXObject ("Msxml2.xmlhttp");}
catch (E2) {
try {xmlhttp=new ActiveXObject ("Microsoft.XMLHTTP");}
catch (E3) {Xmlhttp=false}
}
}
if (! XMLHttp) return false;
This.method= "POST";
This.url= ""
This.url + = (this.url.indexOf ("?") >= 0)? "&nowtime=" + new Date (). GetTime (): "? nowtime=" + new Date (). GetTime ();
This.async=true;
This.data= "";
Objself.loadid= ""
This.backtext=true
This.callback=function () {return;}

This.send=function () {
if (!this.method| |! this.url| |! This.async) return false;
Xmlhttp.open (This.method, This.url, This.async);
if (this.method== "POST") {
Xmlhttp.setrequestheader ("Content-length", (This.data). Length);
Xmlhttp.setrequestheader ("Content-type", "application/x-www-form-urlencoded");
}

Xmlhttp.onreadystatechange=function () {
if (xmlhttp.readystate==4) {
alert (Objself.loadid);
if (objself.loadid!= "") $CS (Objself.loadid, "none");
Window.status= "";
if (xmlhttp.status==200) {
Objself.callback ();
}
}
else {
if (objself.loadid!= "") $CS (Objself.loadid, "block");
window.status= "Status: [" +xmlhttp.readystate+ "] loading ...";
}
}

if (this.method== "POST") xmlhttp.send (This.data);
else xmlhttp.send (NULL);
}

This.gettext=function () {
if (xmlhttp.readystate==4) {
if (xmlhttp.status==200) {
if (this.backtext==true) {
return xmlhttp.responsetext;
}else{
return xmlhttp.responsexml;
}
}
}
}
}



Blog.js
Copy Code code as follows:

Open and close the left column
function $SHleft (ID) {
if ($ (ID). style.display== ' None ') {
$ (ID). style.display= ' block ';
$ ("content"). Style.width= ' 550px ';
$F ("sh", "Hide left column");
}
else{
$ (ID). style.display= ' None ';
$ ("content"). Style.width= ' 750px ';
$F ("sh", "Open left column");
}
}
Turn comments on and off
function $PL (id,plid) {
if ($ ("RP" +id). style.display== ' None ') {
$ ("RP" +id). style.display= ' block ';
$F ("pl" +id, "hidden comment");
Replycon (ID, "RP" +id);
}
else{
$ ("RP" +id). style.display= ' None ';
$F ("pl" +id, "view Comments");
}
}

Show log
Function Show (ID,PAGEID,RQ) {
var ajaxobj=new AJAX ();
Ajaxobj.method= "Get";
Ajaxobj.loadid= "Loadnews";
Ajaxobj.url= "lib.asp?action=show&sid=" +id+ "&rq=" +escape (RQ) + "&page=" +pageid;
Ajaxobj.callback=function () {
$F ("Bkcon", Ajaxobj.gettext ());
}
Ajaxobj.send ();
}
Show log Category List
Function Board () {
var ajaxobj=new AJAX ();
Ajaxobj.method= "Get";
Ajaxobj.loadid= "Loadnews";
Ajaxobj.url= "Lib.asp?action=board";
Ajaxobj.callback=function () {
$F ("Blogcon", Ajaxobj.gettext ());
}
Ajaxobj.send ();
}

Get Comment content
function Replycon (rid,rpid) {
var ajaxobj=new AJAX ();
Ajaxobj.method= "Get";
Ajaxobj.loadid= "Loadnews";
Ajaxobj.url= "lib.asp?action=replycon&rid=" +rid;
Ajaxobj.callback=function () {
$F (Rpid,ajaxobj.gettext ());
}
Ajaxobj.send ();
}

Number of comments made
function Plnum (RID) {
var ajaxobj=new AJAX ();
Ajaxobj.method= "Get";
Ajaxobj.loadid= "Loadnews";
Ajaxobj.url= "lib.asp?action=plnum&rid=" +rid;
Ajaxobj.callback=function () {
$F ("Plnum" +rid,ajaxobj.gettext ());
}
Ajaxobj.send ();
}

Load Post Comment form
function Rform (RID) {
var ajaxobj=new AJAX ();
Ajaxobj.method= "Get";
Ajaxobj.loadid= "Loadnews";
Ajaxobj.url= "lib.asp?action=rform&rid=" +rid;
Ajaxobj.callback=function () {
$F ("Plform" +rid,ajaxobj.gettext ());
}
Ajaxobj.send ();
}

Add Comment content
function Savepl (RID) {
var ajaxobj=new AJAX ();
Ajaxobj.method= "POST";
Ajaxobj.loadid= "Loadnews";
Ajaxobj.url= "lib.asp?action=savepl&";
Ajaxobj.data= "rid=" +rid+ "&username=" +escape ($ ("username" +rid). Value) + "&con=" +escape ($ ("con" +rid). Value );
Ajaxobj.callback=function () {
$F ("TJPL" +rid,ajaxobj.gettext ());
if (Ajaxobj.gettext (). IndexOf ("comment has been submitted successfully") >=0) {
If the comment is successful, close the form and regain the number of comments. Close Success Message
$CS ("Rform" +rid, "none");
Plnum (RID);
Pltjid= "Pltjsuc" +rid;
SetTimeout (' $CS (Pltjid, ' none ') ', 1000);
}
}
Ajaxobj.send ();
}
Show Calendar
function RL (reqdate) {
var ajaxobj=new AJAX ();
Ajaxobj.method= "Get";
Ajaxobj.loadid= "Loadnews";
Ajaxobj.url= "lib.asp?action=rl&reqdate=" +reqdate;
Ajaxobj.callback=function () {
$F ("Calendarcon", Ajaxobj.gettext ());
}
Ajaxobj.send ();
}
Show Message form
function GB () {
var ajaxobj=new AJAX ();
Ajaxobj.method= "Get";
Ajaxobj.loadid= "Loadnews";
Ajaxobj.url= "LIB.ASP?ACTION=GB";
Ajaxobj.callback=function () {
$F ("Gbform", Ajaxobj.gettext ());
}
Ajaxobj.send ();
}

Submit a message
function Savegb () {
var gbusername=$ ("Gbusername"). Value;
var gbemail=$ ("Gbemail"). Value;
var gbcon=$ ("Gbcon"). Value;
Alert ($ ("Gbusername"). Value);
Alert ($ ("Gbemail"). Value);
Alert ($ ("Gbcon"). Value);
return false;
if (gbusername== "") {
$CS ("Gberr", "block");
$F ("Gberr", "Please call on your name");
SetTimeout (' $CS ("Gberr", "none") ', 2000);
return false;
}
if (gbemail== "") {
$CS ("Gberr", "block");
$F ("Gberr", "Please write your mailbox");
SetTimeout (' $CS ("Gberr", "none") ', 2000);
return false;
}
if (gbcon== "") {
$CS ("Gberr", "block");
$F ("Gberr", "Please express your opinion");
SetTimeout (' $CS ("Gberr", "none") ', 2000);
return false;
}
var ajaxobj=new AJAX ();
Ajaxobj.method= "POST";
Ajaxobj.loadid= "Loadnews";
Ajaxobj.url= "lib.asp?action=addgb&";
Ajaxobj.data= "Username=" +escape (gbusername) + "&email=" +escape (gbemail) + "&con=" +escape (Gbcon);
Ajaxobj.send ();
Ajaxobj.callback=function () {
if (Ajaxobj.gettext (). IndexOf ("Success") >=0) {
$SHwin ("GB");
SHOWGB (1);
}
}
}
Show message
function SHOWGB (PageID) {
var ajaxobj=new AJAX ();
Ajaxobj.method= "Get";
Ajaxobj.loadid= "Loadnews";
Ajaxobj.url= "lib.asp?action=showgb&page=" +pageid;
Ajaxobj.callback=function () {
$F ("Bkcon", Ajaxobj.gettext ());
}
Ajaxobj.send ();
}

Current 1/3 page 123 Next read the full text
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.