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