eZe616 Posted July 16, 2007 Share Posted July 16, 2007 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 More sharing options...
eZe616 Posted July 16, 2007 Author Share Posted July 16, 2007 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 https://forums.phpfreaks.com/topic/60142-solved-ajax-login-form/#findComment-299221 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.