Reputation: 175
I have this piece of Javascript:
<script type="text/javascript" src="sha512.js"></script>
<script type="text/javascript" src="forms.js"></script>
<script>
function loadXMLDoc(form, password)
{
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.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
formhash(form, password);
}
}
xmlhttp.open("POST","post.php",true);
xmlhttp.send();
}
</script>
And some HTML:
<div id="myDiv">
<form action="register.php" method="post">
Email: <input type="text" name="email" /><br />
Username: <input type="text" name="username" /><br />
Password: <input type="password" name="p" id="password" /><br />
<input type="button" value="Register" onclick="loadXMLDoc(this.form, this.form.password);" />
</form>
</div>
The Javascript code above has the job to run some Ajax with PHP and after that, run a encryption function (formhash). When the Ajax is run, it reads a page named "post.php" the post.php's job is to check if any of the fields are empty, before the password is encrypted.
My problem is that post.php can't remember that there is any values from the Register form which I posted above. post.php has to remember what the user typed in the fields, in order to see if they are empty or not. Any ideas on, how I can transfer those values to the post.php file?
Upvotes: 0
Views: 210
Reputation: 1853
You can try:
parameters= 'username='+ form.elements[0].value +'&' +'password=' +form.elements[1].value ;
xmlhttp.open("POST","post.php",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send(parameters);
Upvotes: 1
Reputation: 3778
looks like you are not submitting any data to server in the below line:
xmlhttp.open("POST","post.php",true);
You can try below code to send data:
xmlhttp.open("POST","post.php",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("[email protected]&username=Ford&p=pass123");
Upvotes: 1