problems fetching data response

I am trying to work on an assignment to fetch a data response. But, when I bring it up in a browser and click on it, instead of bringing up the right message it brings up all of them and I cant figure out why.

<!--Startwith index.html-->
<html>
<head>
<script type="text/javascript">
function fetchData(url, dataToSend, objectID){
	var pageRequest = false;
	if (window.XMLHttpRequest) pageRequest = new XMLHttpRequest();
	else if (window.ActiveXObject) pageRequest = new ActiveXObject("Microsoft.XMLHTTP");
	else return false;
	pageRequest.onreadystatechange = function() {
		var object = document.getElementById(objectID);
		object.innerHTML = pageRequest.responseText;
	}
	if (dataToSend) {
		var sendData = 'sendData=' + dataToSend;
	pageRequest.open('POST', url, true);
	pageRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	pageRequest.send(sendData);
	}
	else {
	pageRequest.open('GET', url, true);
	pageRequest.send(null);
}}
/*******************************
** Technique 2: Sending Data  **
*******************************/
</script>
<body>
<body background="lilo12b.jpg">
<h1>Which Lilo & Stitch character are you?</h1>
<div id="control"
	onclick="fetchData('dataPage2.php',1,'message');">Lilo</div>
<div id="control"
	onclick="fetchData('dataPage2.php',2,'message');">Stitch</div>
<div id="control"
	onclick="fetchData('dataPage2.php',3,'message');">Jumba</div>
<div id="control"
	onclick="fetchData('dataPage2.php',4,'message');">Pleakley</div>
<p>&nbsp</p>
<div id="message">&nbsp;</div>
<br><br>
<a href="index.html">Home</a>
</body>
</html>
<?php
if(isset($_POST["sendData"]))
{ $searchString = $_POST["sendData"];
	if ($searchString == 1) $dataResults =
		sprintf("<h1>Hello Lilo!</h1>");
	else if ($searchString == 2) $dataResults =
		sprintf("<h1>Hello Stitch!</h1>");
	else if ($searchString == 3) $dataResults =
		sprintf("<h1>Hello Jumba!</h1>");
	else if ($searchString == 4) $dataResults =
		sprintf("<h1>Hello Pleakley!</h1>");
	else $dataResults =
		sprintf("<h1>Aloha, cousin!  Welcome to Hawaii!</h1>");
}
echo $dataResults;
?>

What have you done to try and debug the problem? Where do you think the problem might be? Is the problem with the PHP or the JavaScript?

I think more info is needed.

Sponsor our Newsletter | Privacy Policy | Terms of Service