[-Project essay-] Ajax application in tapestry

Source: Internet
Author: User

Instance:

1. Ajax login advantages: If the entered password is incorrect, the page will be refreshed.

<Script language = "JavaScript">

// Define the XMLHTTPRequest object instance
VaR http_request = false;
// Define reusable HTTP request sending Functions
Function send_request (method, URL, content, responsetype, callback) {// initialize, specify the processing function, and send the request Function
Http_request = false;
// Start initializing the XMLHTTPRequest object
If (window. XMLHttpRequest) {// Mozilla Browser
Http_request = new XMLHttpRequest ();
If (http_request.overridemimetype) {// sets the mime category
Http_request.overridemimetype ("text/XML ");
}
}
Else if (window. activexobject) {// IE browser
Try {
Http_request = new activexobject ("msxml2.xmlhttp ");
} Catch (e ){
Try {
Http_request = new activexobject ("Microsoft. XMLHTTP ");
} Catch (e ){}
}
}
If (! Http_request) {// exception. An error occurred while creating the object instance.
Window. Alert ("the XMLHTTPRequest object instance cannot be created .");
Return false;
}
If (responsetype. tolowercase () = "text "){
// Http_request.onreadystatechange = processtextresponse;
Http_request.onreadystatechange = callback;
}
Else if (responsetype. tolowercase () = "XML "){
// Http_request.onreadystatechange = processxmlresponse;
Http_request.onreadystatechange = callback;
}
Else {
Window. Alert ("response type parameter error. ");
Return false;
}
// Determine the request sending method and URL and whether to asynchronously execute the next code
If (method. tolowercase () = "get "){
Http_request.open (method, URL, true );
Http_request.setrequestheader ("If-modified-since", "0 ");
}
Else if (method. tolowercase () = "Post "){
Http_request.open (method, URL, true );
Http_request.setrequestheader ("Content-Type", "application/X-WWW-form-urlencoded ");
}
Else {
Window. Alert ("the HTTP request type parameter is incorrect. ");
Return false;
}
Http_request.send (content );
}
// Function for processing the returned text format information
Function processtextresponse (){
If (http_request.readystate = 4) {// judge the object status
If (http_request.status = 200) {// The information has been returned successfully. Start to process the information.
// Alert (http_request.responsetext );
Alert ("Text Document response. ");
} Else {// The page is abnormal.
Alert ("the page you requested has an exception. ");
}
}
}

Function registercheck (){
Document. getelementbyid ("feedback_info"). innerhtml = "";
VaR F = Document. Forms [0];
If (F. useraccount. value! = "" & F. Password. value! = ""){
Document. getelementbyid ("feedback_info"). innerhtml = "processing the request. Please wait ...";
Send_request ("Post ","? Service = page/register & useraccount = "+ F. useraccount. Value +" & Password = "+ F. Password. Value, null," text ", showfeedbackinfo );
}
Else {
Document. getelementbyid ("feedback_info"). innerhtml = "enter the correct user name and password. ";
}
}
Function showfeedbackinfo (){
If (http_request.readystate = 4) {// judge the object status
// Alert (http_request.responsetext );
If (http_request.status = 200) {// The information has been returned successfully. Start to process the information.
// Alert (http_request.responsetext );
If (http_request.responsetext = 'OK '){
Document. Forms [0]. Submit ();
}
Else {
Document. getelementbyid ("feedback_info"). innerhtml = http_request.responsetext;
}

} Else {// The page is abnormal.
Alert ("the page you requested has an exception. ");
}
}
}
</SCRIPT>

2. Ajax implements timed refresh. (To be continued)

 

 

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.