_Csandeep

Ajax Form Submit - PHP

Aug 10th, 2013 (edited)
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.72 KB | None | 0 0
  1. <!-- Form submit with AJAX passing form data to PHP without page refresh -->
  2. <!DOCTYPE HTML>
  3. <html>
  4.     <head>
  5.     <title>Ajax Form Submit Example</title>
  6.     <script src="js/jquery-1.10.2.js"></script>
  7.     <script>
  8.         $(function() {
  9.            $('form').on('submit', function(e) {
  10.               $.ajax({
  11.              type : 'post',
  12.              url : 'post.php',
  13.              data : $('form').serialize(),
  14.                success : function() {
  15.                alert('Form was submitted');
  16.              }
  17.                });
  18.           e.preventDefault();
  19.         });
  20.            });
  21.      </script>
  22.    </head>
  23. <body>
  24.    <form>
  25.     <input name="name" value="" required="">
  26.     <br>
  27.     <input name="password" value="" required="">
  28.     <br>
  29.     <input name="submit" type="submit" value="Submit">
  30.    </form>
  31. </body>
  32. </html>
Add Comment
Please, Sign In to add comment