Sending POST with javascript
What is wrong with this code? Trying to send data over POST w/ javascript
to a PHP page but it isn't sending anything, nothing comes across in the
headers $_POST contains nothing.
HTML:
<form method="POST" id="userSub" class="userSub">
<table>
<tr><td colspan="2">Sign In Here </td></tr>
<tr><td>Username:</td><td><input name="username" type="text"
id="username" /></td></tr>
<tr><td>Password:</td><td><input name="pwd" type="text" id="pwd"
/></td></tr>
<tr><td><input name="submit" type="submit" value="submit" id="submit"
onclick="loginSub()" /></td></tr>
<tr><td colspan="2">Need a Username? <a href="signup.html">Sign
Up</a></td></tr>
</table>
</form>
Javascript:
function loginSub(){
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("rssnav2").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("POST","PHP/login.php",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send();
}
PHP doesn't do anything special right now, just seeing if I can pass the
post information to it:
<?php
echo "test";
$username=$_POST['username'];
echo $username;
?>
It is IS echoing that 'test' line to the correct so it is communicating w/
the PHP page. Also, I know that I still have the pwd input in "text" type
and I know its probably a good idea to hash a password before sending it
to the server.
Thanks for your help, everyone!
No comments:
Post a Comment