ex #1)
<script language="javascript" type="text/javascript"> <!-- function getXMLHttps() {
if (typeof XMLHttpRequest != 'undefined') { return new XMLHttpRequest(); } else { try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try{ return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){ alert("Ajax를 지원하는 브라우저가 아닙니다."); return false; } } } }
function dynamic(){ var http = getXMLHttps();
http.onreadystatechange = function(){ if ((http.readyState === 4) && (http.status === 200)) { document.getElementById("Prints").innerHTML = http.responseText; } }
var name = document.getElementById('name').value; var age = document.getElementById('age').value;
http.open("POST", "test.php", true);
http.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded' );
http.setRequestHeader( 'Cache-Control', 'no-cache' );
http.send( "name=" + encodeURIComponent(name) + "&age=" + encodeURIComponent(age) ); } //--> </script> <!-- test.php print_r($_POST); -->
<form name='forms'> Name: <input type='text' id='name' value="habony" /><br /> age: <input type='text' id='age' value="15" /> <input type='button' onclick='dynamic()' value='Send' /> </form> <br /><br /> <div id="Prints"></div>
</body> </html> <!-- 출력: Array ( [name] => habony [age] => 15 ) --> |