Page 1/3 of several functions used by Ajax blog

Source: Internet
Author: User

Class Name: Ajax CopyCode The Code is as follows:/* Class Name: Ajax

Creation Method: var ajaxobj = new Ajax;. If creation fails, false is returned.

Attribute: method-Request Method, String, post, or get. The default value is post.
URL-request URL, String, empty by default
Async-asynchronous or not. True indicates asynchronous, and false indicates synchronous. The default value is true.
Content-the content of the request. If the request method is post, this attribute must be set. The default value is null.
Backtext-the default value is true. If backtext is set to true, XMLHTTP. responsetext is returned to be false, and XMLHTTP. responsexml is returned.
Gettext-Return Value
The callback-callback function is the function called when the response content is returned. The default value is direct return. The callback function has a parameter XMLHTTPRequest object, that is, the callback function must be defined as follows: function mycallback (xmlobj)

Method: Send ()-Send request, no Parameter

*/

function Ajax () {
var XMLHTTP = false;
var objself;
objself = This;
try {XMLHTTP = new XMLHttpRequest ;}
catch (e) {
try {XMLHTTP = new activexobject ("msxml2.xmlhttp") ;}< br> catch (E2) {
try {XMLHTTP = new activexobject ("Microsoft. XMLHTTP ") ;}< br> catch (E3) {XMLHTTP = false ;}< BR >}< br> 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. jsCopy codeThe Code is 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 the left column ");
}
}
// Open and Close comments
Function $ pL (ID, plid ){
If ($ ("RP" + id). style. Display = 'None '){
$ ("RP" + id). style. Display = 'block ';
$ F ("PL" + id, "Hide comments ");
Replycon (ID, "RP" + id );
}
Else {
$ ("RP" + id). style. Display = 'none ';
$ F ("PL" + id, "view comments ");
}
}

// Display logs
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 ();
}
// Display the 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 comments
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 retrieved
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 the 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 comments
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 ("comments submitted successfully")> = 0 ){
// If the comments are submitted successfully, the form is closed and the number of comments is retrieved again. Message indicating successful Shutdown
$ CS ("rform" + RID, "NONE ");
Plnum (RID );
Pltjid = "pltjsuc" + RID;
SetTimeout ('$ CS (pltjid, "NONE")', 1000 );
}
}
Ajaxobj. Send ();
}
// Display 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 ();
}
// Display the 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 post your name ");
SetTimeout ('$ CS ("gberr", "NONE")', 2000 );
Return false;
}
If (gbemail = ""){
$ CS ("gberr", "Block ");
$ F ("gberr", "please write your email address ");
SetTimeout ('$ CS ("gberr", "NONE")', 2000 );
Return false;
}
If (gbcon = ""){
$ CS ("gberr", "Block ");
$ F ("gberr", "Please post 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 ("successful")> = 0 ){
$ Shwin ("GB ");
Showgb (1 );
}
}
}
// Display the 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 ();
}

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.