PHP ajax XMLHttpRequest Post Instance code

Source: Internet
Author: User
Keywords Web Programming PHP Tutorials
Tags ajax code content html http php php tutorial programming

PHP Tutorial Ajax XMLHttpRequest Post Instance code
<! DOCTYPE HTML PUBLIC "-//w3c//dtd XHTML 1.1//en" "Http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" >
<html xmlns= "Http://www.jzread.com/1999/xhtml" >
<meta http-equiv= "Content-type" content= "Text/html;charset=utf-8"/ >
<head>

<script type= "text/javascript Tutorial"
function Showuser (str) {
    if window. XMLHttpRequest) {//code for ie7+, Firefox, Chrome, Opera, Safari
        XMLHTTP =new XMLHttpRequest ();
   }else{//code for IE6, IE5
        xmlhttp=new ActiveXObject ("Microsoft.XMLHTTP");
   }
    xmlhttp.onreadystatechange=function () {
        if ( Xmlhttp.readystate==4 && xmlhttp.status==200) {
             document.getElementById ("Txthint"). Innerhtml=xmlhttp.responsetext;
       }
   }
    xmlhttp.open ("POST", "ajax.php", true);
    xmlhttp.setrequestheader ("Content-type", "Application/x-www-form-urlencoded;charset=utf-8 ;");
    XMLHttp.send (' q= ' +str);
}
</script>
</head>

<body>
<form method= "POST" >
Ajax Post<input Name= "submit" type= "Submit" onclick= "Showuser"; return false; "value=" Query/>
</form>
<form action= "ajax.php" method= "POST" >
Real Post<input name= "q" type= "submit" value= "/>"
</form>
<br/>
<div id= "Txthint" ><b>person info would be listed here.</b></div>
</body>
</html>
PHP code

<?php
Header (' content-type:text/html;charset=utf-8; ');
echo "Post data:". Implode (', File (' Php://input '));
echo "<br>post[q]". $_post[' Q '. " <br> ";
Print_r ($_post);
?>

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.