javascript - jQuery $.post-function | data-processing function does not work -


i new in web development, having years of experience in traditional development, e.g. using java, c , abap, under belt.

i trying create pretty simple login-functionality, struggling jquery's $.post()-functionality.

in below seen code, alert("test")-function in data-processing part of $.post() doesn´t seem executed, after submit form form_login. guess problem how connected javascript-function login_attempt() submitting of form form_login.

<!doctype html>  <html>  <head>  	<title>login</title>    	<script src="jquery-2.2.4.min.js"></script>    	<script>  	function login_attempt(){  		$.post("login.php", $("#form_login").serialize(), function(data){alert("test");},html);  	}  	</script>    </head>  <body>  	<h1>login-form</h1>	  	<form id="form_login" method="post" onsubmit="return login_attempt()">  		<p><label for="id_username">username: </label><input id="id_username" name="username" type="text" width="20"></label></p>  		<p><label for="id_password">password: </label><input id="id_password" name="password" type="password" width="10"></label></p>  		<p><input type="submit" name="submit_login"></p>  	</form>    		  </body>  </html>

the function login_attempt triggered when submitting form , after form submitted since login_attempt function not tell form stop submitting in regular way. therefor page reloads before actual callback of post method anything.

add return false; last line of login_attempt function tell form should not submit in regular way.


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -