A simple Ajax

Source: Internet
Author: User
Because the template page is long, only Ajax is logged out. Code Part, that is, the part before the <body> label
 <!  Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"  >  
< Script Type = "Text/JavaScript" Language = "JavaScript" >
// Create functions for XMLHttpRequest objects with multiple browsers
Function Getxmlrequester (){
VaR Xmlhttp_request = False ;
Try {
If (Window. activexobject ){
For ( VaR I = 5 ; I -- ){
Try {
If (I = 2 ) {Xmlhttp_request = Newactivexobject ( " Microsoft. XMLHTTP " );
} Else {Xmlhttp_request = New Activexobject ( " Msxml2.xmlhttp. " + I + " . 0 " );
Xmlhttp_request.setrequestheader ( " Content-Type " , " Text/XML " ); Xmlhttp_request.setrequestheader ( " Content-Type " , " Gb2312 " );
}
Break ;}
Catch (E ){
Xmlhttp_request = False ;
}
}
} Else If (Window. XMLHttpRequest ){
Xmlhttp_request = New XMLHttpRequest ();
If (Xmlhttp_request.overridemimetype ){
Xmlhttp_request.overridemimetype ('text / Xml ');
}
}
}
Catch (E ){
Xmlhttp_request = False ;
}
Return Xmlhttp_request;
}
Function Idrequest (){
// Defines the JavaScript function to be executed after receiving the response from the server.
URL = 'Checklogin. aspx' // Define URL parameters
// Alert (URL );
Xmlhttp_request = Getxmlrequester (); // Call the function for creating XMLHttpRequest
Xmlhttp_request.onreadystatechange = Docontents; // Call the docontents Function
Xmlhttp_request.open ('post', URL, True );
Xmlhttp_request.send ( Null );
}
Function Docontents (){
If (Xmlhttp_request.readystate = 4 ){ // Receives the complete Server Response
If (Xmlhttp_request.status = 200 ){ // The HTTP server response value is OK.
VaR Str = Xmlhttp_request.responsetext; // Write the string returned by the server to the region where the ID is message on the page.
If (Str. Length > 583 )
{
// Self. Location = "../login. aspx ";
Location. href = '.. / Login. aspx ';
}
} Else {
Alert (http_request.status );
}
}
}
Idrequest ();
</ Script >
< Html Xmlns = "Http://www.w3.org/1999/xhtml" >
< Head Runat = "Server" >
< Title > $ Chapter $ --> $ order $ --> $ title $ </ Title >
< Link Href = "../Stylesheet.css" REL = "Stylesheet" Type = "Text/CSS" />
</ Head >
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.