Ajax post read comments

Source: Internet
Author: User

Copy codeThe Code is as follows:
--------------------------- Jack's Annotation ajaxJS. js -----------------------------

// A waiting window is displayed.
Document. write ('<DIV id = "loadingg" style = "HEIGHT: 65px; WIDTH: 205px; POSITION: absolute; Z-INDEX: 1000; border: 3px # fff solid; text-align: center; font-size: 12px; font-family: Arial, Helvetica, sans-serif; color: #660000; background: #222; opacity :. 7;-moz-opacity :. 7; filter: alpha (opacity = 70); display: none; "> <br/> <font color =" # FF6600 "> <strong> the data is being read, please wait... </strong> </font> <br/> </DIV> ')
// Showloading controls the display and hiding of the waiting window
Function showloading ()
{
Var obj = document. getElementById ("loadingg ")
If (obj. style. display! = "")
{
Obj.style.left.pdf (document.doc umentElement. clientWidth-parseFloat (obj. style. width)/2)+document.doc umentElement. scrollLeft + "px ";
Obj.style.topight (document.doc umentElement. clientHeight-parseFloat (obj. style. height)/2)+document.doc umentElement. scrollTop + "px ";
Obj. style. display = "";
} Else {obj. style. display = "none ";}
}

// $ () Gets the object with the specified ID
Function $ (id)
{
Return document. getElementById (id );
}
// Echo () shows the specified html to the specified object obj
Function echo (obj, html)
{
$ (Obj). innerHTML = html;
}
// Fopen () indicates that the specified obj is displayed.
Function fopen (obj)
{
$ (Obj). style. display = "";
}
// Fclose () to hide the specified obj
Function fclose (obj)
{
$ (Obj). style. display = "none ";
}
// Createxmlhttp () gets the XMLHttpRequest object and returns
Function createxmlhttp ()
{
Var xmlhttp = false;
Try {
Xmlhttp = new ActiveXObject ("Msxml2.XMLHTTP ");
}
Catch (e ){
Try {
Xmlhttp = new ActiveXObject ("Microsoft. XMLHTTP ");
}
Catch (e ){
Xmlhttp = false;
}
}
If (! Xmlhttp & typeof XMLHttpRequest! = 'Undefined '){
Xmlhttp = new XMLHttpRequest ();
If (xmlhttp. overrideMimeType) {// sets the MiME category
Xmlhttp. overrideMimeType ('text/xml ');
}
}

Return xmlhttp;
}
// The data obtained from the specified URL by getdata () is displayed in obj2. obj1 is the prompt information in this process and can be deleted.
Function getdata (url, obj1, obj2)
{
Var xmlhttp = createxmlhttp ();
If (! Xmlhttp)
{
Alert ("your browser does not support XMLHTTP !! ");
Return;
}
Showloading ()
Xmlhttp. onreadystatechange = requestdata;
Xmlhttp. open ("GET", url, true );
Xmlhttp. send (null );
Function requestdata ()
{

Fopen (obj1 );
// Echo (obj1, "loading data. Please wait ......");
// Alert (xmlhttp. readyState)
If (xmlhttp. readyState = 4)
{
If (xmlhttp. status = 200)
{
If (obj1! = Obj2) {fclose (obj1 );};
Echo (obj2, xmlhttp. responseText );
Showloading ()
}
}

}
}
// Postdata () sends the specified data to the url address and uses obj to display the returned data
Function postdata (url, obj, data)
{Var rnd = Math. random ()
Var xmlhttp = createxmlhttp ();
If (! Xmlhttp)
{
Alert ("your browser does not support XMLHTTP !! ");
Return;
}
Showloading ()
Xmlhttp. open ("POST", url, true );
Xmlhttp. onreadystatechange = requestdata;
Xmlhttp. setRequestHeader ("Content-Type", "application/x-www-form-urlencoded ");
Xmlhttp. send (data );
Function requestdata ()
{
Fopen (obj );
Echo (obj, "submitting data. Please wait ......");
If (xmlhttp. readyState = 4)
{
If (xmlhttp. status = 200)
{
Echo (obj, xmlhttp. responseText );
Reget (rnd );
SetTimeout ("echo ('showresult','') ", 2000 );
Echo ('message ','')
Showloading ()
}
}
}
}
// LTrim () removes the space on the left of the string
Function lTrim (str)
{
If (str. charAt (0) = "")
{
// If the first character on the left of the string is a space
Str = str. slice (1); // remove spaces from the string
// This sentence can also be changed to str = str. substring (1, str. length );
Str = lTrim (str); // recursive call
}
Return str;
}

// Remove the space on the right of the string from rTrim ()
Function rTrim (str)
{
Var iLength;

ILength = str. length;
If (str. charAt (iLength-1) = "")
{
// If the first character on the right of the string is a space
Str = str. slice (0, iLength-1); // remove spaces from the string
// This sentence can also be changed to str = str. substring (0, iLength-1 );
Str = rTrim (str); // recursive call
}
Return str;
}

// Trim () removes spaces on both sides of the string
Function trim (str)
{
Return lTrim (rTrim (str ));
}


// F () has no general meaning and only applies to specific objects.
Function f (obj)
{
Return trim (eval ("document. ajax_post." + obj + ". value "));
// Return trim ($ (obj). value );
}
// SaveReply () is a form check and submission function.
Function SaveReply ()
{
If (f ("username") = "")
{
Alert ("Enter the user name ");
Return false;
}
If (f ("Message") = "")
{
Alert ("content cannot be blank ");
Return false;
}
Var validate, password, log_DisKey = 0, log_DisURL = 0, log_DisSM = 0
Validate = ""
Password = ""
If (document. ajax_post.log_DisKey.checked ){
Log_DisKey = f ("log_DisKey ")
}
If (document. ajax_post.log_DisURL.checked ){
Log_DisURL = f ("log_DisURL ")
}
If (document. ajax_post.log_DisSM.checked ){
Log_DisSM = f ("log_DisSM ")
}
If (typeof eval (document. ajax_post.validate ))! = "Undefined "){
If (f ("validate") = "")
{
Alert ("Please enter the Verification Code ");
Return false;
} Else {
Validate = f ("validate ");
}
}
If (typeof eval (document. ajax_post.password ))! = "Undefined "){
Password = f ("password ");
}
Data = "username =" + escape (f ("username") + "& password =" + escape (password) + "& validate =" + escape (validate) + "& log_DisSM =" + escape (log_DisSM) + "& log_DisURL =" + escape (log_DisURL) + "& log_DisKey =" + escape (log_DisKey) + "& Message =" + escape (f ("Message") + "& logID =" + escape (f ("logID ")) + "& action =" + escape (f ("action "));
// Alert (data );
Postdata ("wbc_blogcomm.asp", "showresult", data );
Return true;
}


Call:
Copy codeThe Code is as follows:
<Div id = ShowComm> </div>
<Script language = "javascript" type = "text/javascript" src = "ajaxJS. js"> </script>
<Script language = "javascript" type = "text/javascript">
Function reget (str ){
Getdata ('wc _ ShowComm. asp? LogID = 100 & comDesc = Desc & DisComment = False & 0.5675318 & '+ str, 'showcomm', 'showcomm ');
}
Reget ('get ');
</Script>

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.