Jump to content

[SOLVED] ajax login form...


eZe616

Recommended Posts

 

Ok...I'm fairly new to ajax. I'm trying to build a simple ajax login form.

I got so stuck that I'm just trying to understand getting POST values with the .open method.

 

The Javascript I have so far is

function ajaxfuntion()
{
	var input1 = document.getElementById("text").value;

	xmlhttp.open("POST",t.php);
	xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlhttp.onreadystatechange = function (){
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200 )
			{
				document.getElementById("loginf").innerHTML = xmlhttp.responseText;
			}
		 }
	xmlhttp.send(input1);

}

</script>

 

The .php file to process the values being send

<?php 

$txt = $_POST["text"];

echo $txt;

?>

 

The HTML form code is as follow

<div class="loginf">

<form action="" name="test" id="test" onSubmit="ajaxfunction(); return false;" method="post">
<fieldset>
<label>
<input type="text" name="text" id="text" maxlength="32" class="user" />
    </label>
    <label>
    <input type="submit" value="test"/>
    </label>
    </fieldset>
</form>
</div>

 

What I'm trying is to get the .php's echo statement to replace the form in the loginf div

 

Is there anything wrong with my code?

Link to comment
https://forums.phpfreaks.com/topic/60142-solved-ajax-login-form/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.