Ajax.html
Program code
Copy codeThe Code is as follows:
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<Title> AJAX entry-level instances compatible with multiple browsers (ultra-detailed comments) </title>
<Script type = "text/javascript">
<! --
// Ajax is a technology built on the XMLHttp component. For detailed syntax in this example, refer to the xmlhttp manual in the compressed package.
Var xmlHttp
// Create an XMLHTTP object to call the ActiveXObject method of MS. If the method is successful (IE browser) if you use MS ActiveX to create an XMLHTTP object instead of IE, you can create an XMLHttp object for a local Javascript Object (this method ensures AJAX support in different browsers)
Function createXMLHttp (){
If (window. XMLHttpRequest) {// Mozilla Browser
XmlHttp = new XMLHttpRequest ();
} Else if (window. ActiveXObject) {// IE browser
Try {
XmlHttp = new ActiveXObject ("Msxml2.XMLHTTP ");
} Catch (e ){
Try {
XmlHttp = new ActiveXObject ("Microsoft. XMLHTTP ");
} Catch (e ){}
}
}
}
// Establish the main process
Function startXMLHttp (){
CreateXMLHttp (); // create an xmlHttp object
Var send_string = "name =" + document. getElementById ("name"). value;
Send_string = encodeURI (send_string)
// Alert (document. getElementById ("text"). value );
// Return;
XmlHttp. onreadyStatechange = dodo; // The onreadystatechange method in xmlHttp controls the transfer process.
XmlHttp. open ("post", "ajax_show.php", true); // whether the page read by the transfer method is asynchronous or not
// XmlHttp. setRequestHeader ("cache-control", "no-cache ");
XmlHttp. setRequestHeader ("Content-Type", "application/x-www-form-urlencoded ");
XmlHttp. send (send_string); // send
}
Function dodo (){
If (xmlHttp. readyState = 4) {// readystate Method 4 in xmlHttp indicates that the transfer is complete.
If (xmlHttp. status = 200) {// xmlHttp's status method reads status (Server HTTP status Code) 200 corresponding to OK 404 corresponding to Not Found (Not Found), etc.
Document. getElementById ("content"). innerHTML = xmlHttp. responseText // The responseText method of xmlHttp to obtain the page data to be read.
}
}
}
-->
</Script>
</Head>
<Body>
<Span id = "content"> content to be replaced </span> <br>
<Input type = "button" onclick = "javascript: startXMLHttp ()" value = "AJAX get"/>
<Form id = "form1" name = "form1" method = "post" action = "">
<Label>
<Input type = "text" name = "name" id = "name"/>
</Label>
</Form>
</Body>
</Html>
Ajax_show.php
Program code
Copy codeThe Code is as follows:
<? Php
$ Content = isset ($ _ POST ['name'])? $ _ POST ['name']: '';
Echo $ content;
?>