php ajax XMLHttpRequest POST实例代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" > <html xmlns= "http://www.111cn.net/1999/xhtml" > <meta http-equiv= "Content-Type" content= "text/html;charset=UTF-8" /> <head> <script type= "text/javascript" > 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;" ); //开源代码phpfensi.com xmlhttp.send( 'q=' +str); } </script> </head> <body> <form method= "post" > ajax的POST<input name= "submit" type= "submit" onclick= "showUser(28);return false;" value= "查询" /> </form> <form action= "ajax.php" method= "post" > 真正的POST<input name= "q" type= "submit" value= "28" /> </form> <br /> <div id= "txtHint" ><b>Person info will be listed here.</b></div> </body> </html> php 代码 <?php header( 'Content-Type:text/html;charset=utf-8;' ); echo "POST数据: " .implode( '' ,file( 'php://input' )); echo "<br>POST[q] " . $_POST [ 'q' ]. "<br>" ; print_r( $_POST ); ?>查看更多关于php ajax XMLHttpRequest POST实例代码 - php高级应用的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://www.haodehen.cn/did30189