Submit comments using Ajax

Source: Internet
Author: User

Copy codeThe Code is as follows:

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> ')
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 ";}
}
Function $ (id)
{Return document. getElementById (id );}
Function echo (obj, html) {$ (obj). innerHTML = html ;}
Function fopen (obj) {$ (obj). style. display = "";}
Function fclose (obj) {$ (obj). style. display = "none ";}
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;
}

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 ()
}
}
}
}
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 ()
}
}
}
}
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 spaces on the right of the string
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;
}

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

Function f (obj)
{
Return trim (eval ("document. ajax_post." + obj + ". value "));
// Return trim ($ (obj). value );
}

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

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.