Hi, I can't figure out what my code is missing. The text input from the 'name' id isn't submitting to the php page,
Here is the html form:
<body>
<form>
Enter name:
<input type="text" id="name">
<input type="button" value="Send" onclick="loadAJAX('phppage.php')">
</form>
<div id="display">
</div>
</body>
This is the AJAX code:
<script type="text/javascript">
function loadAJAX(url)
{
var params = "name=name"
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET",url,false);
//Send the proper header information along with the request
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("Content-length", params.length);
xmlhttp.setRequestHeader("Connection", "close");
xmlhttp.onreadystatechange = function() {//Call a function when the state changes.
if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
alert(xmlhttp.responseText);
}
}
xmlhttp.send(params);
document.getElementById('display').innerHTML=xmlhttp.responseText;
}
</script>
This is the PHP code:
<html>
<body>
Hi <?php echo $_POST["name"];?>
</body>
</html>
The "Hi" displays in the 'display' div, but the 'name' form data does not.
I'm not sure what I'm mising.
*Also about the parameters, I read a tutorial saying to put name=value&name=value for the parameters. But doesn't the input 'id' contain the value to submit to the php page? So what would I put for the value?
Thanks