alankis

AJAX

May 25th, 2015
361
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.91 KB | None | 0 0
  1. #index.php file:
  2. <!doctype html>
  3.     <head>
  4.         <script src="jquery-1.11.3.min.js"></script>
  5.     </head>
  6.     <body>
  7.     <script>
  8.  
  9.  
  10.  
  11.          $('form').submit(function(){
  12.             $.ajax({url: "magic.php",
  13.                     data: {variable : $('#variable').val()},
  14.                     success:function(data){alert(data);});
  15.             return false;
  16.         });
  17.  
  18.     </script>
  19.         <!-- form -->
  20.         <form action="magic.php" method="POST">
  21.             <label for="domain">Unesite varijablu:</label>
  22.             <input type="text" name="variable" id="domain" />
  23.                
  24.             <input type="submit" value="trazi" name="submit"  />
  25.         </form>
  26.     </body>
  27. </html>
  28.  
  29.  
  30. #magic.php file
  31.  
  32. <?php
  33.  
  34.  
  35. /*
  36.  *
  37.  * fetch variable with POST
  38.  */
  39. $variable = $_POST['variable'];
  40.  
  41.  
  42. function doMagic($variable) {
  43.     return  "Variable value is $variable";
  44. }
  45.  
  46. $data = doMagic($variable);
  47.  
  48. return $data;
Advertisement
Add Comment
Please, Sign In to add comment