Ajax POST and GET request
Ajax
Download (.zip)
<script language="javascript"> function createXMLHttpRequest() { if (window.ActiveXObject) { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } else if (window.XMLHttpRequest) { xmlHttp = new XMLHttpRequest(); } } function GETRequest(query) { createXMLHttpRequest(); var queryString = "index.php?" + query; xmlHttp.onreadystatechange = handleStateChange; xmlHttp.open("GET", queryString, true); xmlHttp.send(null); } function POSTRequest(query) { createXMLHttpRequest(); var url = "index.php"; xmlHttp.open("POST", url, true); xmlHttp.onreadystatechange = handleStateChange; xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xmlHttp.send(query); } function handleStateChange() { if(xmlHttp.readyState == 4) { if(xmlHttp.status == 200) { parseResults(); } } } function parseResults() { alert(xmlHttp.responseText); // document.getElementbyId('index').innerHTML = xmlHttp.responseText; }
</script>
<?php foreach ($_REQUEST as $variablename => $value){ echo $variablename.' = '.$value; echo "\n <br>"; } ?>
|