Php ajax post instance code

Source: Internet
Author: User

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

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.