I'm new in Website programming. Recently I'm building a log in website. First I want to find out how does JavaScript send and PHP receive data. My HTML codes are as followed:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>CSS Test</title>
<link type="text/javascript" herf="script.js"/>
</head>
<body>
<div id="div1">
<input placeholder="Username:" class="inputter" id="inputter1"/>
<input placeholder="Password:" class="inputter" id="inputter2"/>
<button onclick="send()" id="button1">Submit</button>
</div>
</body>
</html>
The codes in file 'script.js' are as followed:
function send(){
var xmlhttp;
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('POST','query.php',true)
xmlhttp.send("user="+document.getElementById("inputter1")+"password="+document.getElementById("inputter2"))
}
And the PHP codes are as followed:
<?php
echo "Data received:user is ".$_POST['user']
?>
When I typed in the 'inputter1' and clicked the button, nothing happened. There wasn't any echo on the page. I guess a syntax mistake caused that but I don't know where and how to change that. Please help me. Thanks to any help.