How to submit a form without refresh page

Jquery

Posted on 03 Dec 15 by Vickey
  881



By using jquery we can submit a form without refresh the page.Here is a sample code

File form.html

<script src="jquery.js"></script> 
<form id="contactForm" action="contact.php" method="post"> 
    Name: <input type="text" name="name" />
	Email: <input type="text" name="email" />	
    Message: <textarea name="message"></textarea> 
    <input type="submit" value="Contact Us" /> 
</form>

<script>
   $('#contactForm').submit(function() {
	var getFormData=$('#contactForm').serialize();
	$.post('form.php',getFormData  ,function (response){
		alert(response);
	})
	return false;
});
</script>

File form.php

<?php

	print_r($_POST);

?>

 


If this post help you reduce time to develop, you can help me to maintain this website :)
www.000webhost.com