StealthThrax

Process PHP Script Form without Refresh with display

Jan 7th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.76 KB | None | 0 0
  1. Place inside your head tag
  2. <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
  3.  
  4. Place after your </body> tag
  5. <script type="text/javascript">
  6. $(document).ready(function() {
  7.       $('form').submit(function(e){
  8.        
  9.            $.ajax({
  10.                 type: 'post',
  11.                 url: './folder_name/script_name.php', // or script_name.php
  12.                 data: $('form').serialize(),
  13.                 success: function(result) {
  14.                        $('#response').html("<b>" + result + "</b>")
  15.                 }
  16.            });
  17.            e.preventDefault(); //Doesn't allow page to refresh
  18.       });
  19. });
  20. </script>
  21.  
  22. Place wherever you want outcome to display in your  <body>
  23. <div id="response"></div>
Add Comment
Please, Sign In to add comment