Advertisement
obernardovieira

+[PHP&jQuery] Save info without refresh page

Nov 18th, 2013
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 0.71 KB | None | 0 0
  1. <html>
  2.     <head>
  3.         <script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
  4.         <meta charset="utf-8">
  5.         <script type="text/javascript">
  6.             $(document).ready(function(){
  7.                 $("#entrada").click(function(){
  8.                     $.post("pagephp.php",
  9.                     {
  10.                         name:"Bernardo Vieira",
  11.                         city:"Ponte de Lima"
  12.                     },
  13.                     function(data,status){
  14.                         alert("Data: " + data + "\nStatus: " + status);
  15.                     });
  16.                 });
  17.             });
  18.         </script>
  19.     </head>
  20.     <body>
  21.         <input id="txtentrada" placeholder="texto entrada" ></input>
  22.         <input type="submit" id="entrada"></input>
  23.     </body>
  24. </html>
  25.  
  26.  
  27. //pagephp.php
  28.  
  29. <?php
  30. if(isset($_POST["name"])) {
  31.     echo "Nome: ". $_POST["name"];
  32.     //save info
  33. }
  34. else {
  35.     echo "Nada!";
  36. }
  37. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement