You give your name and email in a field, hit submit and the data is displayed by calling a javascript function.
The php file to read the data is:
Code: Select all
<?php
$userName = $_REQUEST['userName'];
$userEmail = $_REQUEST['userEmail'];
header("Cache-Control : no-cache, must-revalidate" );
header("Expires : Mon, 26 Jul 1995 05:00:00 GMT");
header('Content-type: text/html');
echo "Your Name is: $userName";
echo "<br />";
echo "Your Email is: $userEmail";
?>Code: Select all
<script type="text/javascript" >
var xmlHttp;
function createXMLHttpRequest() {
if (window.ActiveXObject) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if (window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
}
}
function createQueryString() {
var userName = document.getElementById("userName") .value;
var userEmail = document.getElementById("userEmail") .value;
var queryString = "userName=" + userName + "&userEmail=" + userEmail;
return queryString;
}
function doRequestUsingPOST() {
createXMLHttpRequest();
var url = "GetAndPostExample.php";
var queryString = createQueryString();
xmlHttp.open("POST", url, true);
xmlHttp.onreadystatechange = handleStateChange;
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
xmlHttp.send(queryString);
}
function handleStateChange() {
if(xmlHttp.readyState == 4) {
if(xmlHttp.status == 200) {
parseResults();
}
}
}
function parseResults() {
var responseDiv = document.getElementById("serverResponse");
if(responseDiv.hasChildNodes()) {
responseDiv.removeChild(responseDiv.childNodes[0]);
}
var responseText = document.createTextNode(xmlHttp.responseText);
responseDiv.appendChild(responseText);
}
</script>I do have my headers correct, do I?