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
Share on other sites

A head up.. I found a mistake in the code.

 

where class="loginf" -> id="loginf"

and in xmlhttp.open("POST",t.php); -> xmlhttp.open("POST","t.php");

 

but still not working thought

 

ANybody have any idea as to why?

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.