Problem with sending form data with Ajax POST

Hi,

I have a problem with sending data from a form to a php script with AJAX. To test if it works, I try to send data from the form, print it in the php with “echo”, and then put it back in the initial html file.

My Javascript code is:

function registerPrivateUser()
{
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null)
	{
	  alert ("Your browser does not support AJAX!");
	  return;
	}
	
	var postData="firstName="+ document.getElementById("txtFirstName").value;
	var url="classes/users/checkRegistration.php";
	xmlhttp.onreadystatechange=stateChanged;
	xmlhttp.open("POST",url,true);
	//xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); 
	
	xmlhttp.send(postData);
}

The function stateChanged, basically says:

if (xmlhttp.readyState==4)
	{
		var strResponse;
		strResponse=xmlhttp.responseText;
		alert('Response:' + xmlhttp.responseText);
	}

checkRegistration.php looks like this:

<? 
session_start(); 
$firstName=$_POST['firstName']; 
echo($firstName); 
?>

The problem is that the response is empty, but I don’t know why. I have checked the input data and the postData variable says “firstName=”+input (e.g. “firstName=Robert”), so that’s not the error. I have read several forum posts here, but still haven’t figured out what I’m doing wrong.
If anyone could please tell me, I would appreciate it alot.