Guest User

Atualiza Variavel PHP via Ajax sem refresh

a guest
Aug 10th, 2012
3,535
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. echo $_POST["linkNovo"];
  3. ?>
  4. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  5. <html xmlns="http://www.w3.org/1999/xhtml">
  6. <head>
  7. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  8. <title>Teste ajax jquery tutsmais</title>
  9. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"> </script>
  10. <script>
  11.  
  12. // Função
  13. $(function(){
  14.     $('#menu a').click(function(){    /* Conforme menu da div id="menu" os links clicados*/
  15.    
  16.     var recebeLink = $(this).attr('name');  /* Cria variavel nome e depois Pega pelo atributo name do link*/
  17.     //alert(nome);  // Mensagem de alerta
  18.    
  19.     $.ajax({
  20.             type            : 'post',      
  21.              url            : 'index.php',
  22.              data           : 'linkNovo='+ recebeLink,   /*seta que o post tera o nome de linkNovo e atribui a ele o valor do name do link  */
  23.              dataType   : 'html',
  24.              success : function(name){
  25.                     $('body').html(name);
  26.                 }
  27.         });
  28.  
  29.         });
  30.     });
  31. </script>
  32. </head>
  33.  
  34. <body>
  35.     <div id="menu">
  36.      <a href="#"  name="valor1">menu1 </a>
  37.      <a href="#"  name="valor2">menu1 </a>
  38.      <a href="#"  name="valor3">menu1 </a>
  39.      <a href="#"  name="valor4">menu1 </a>
  40.      <a href="#"  name="valor5">menu1 </a>
  41.      <a href="#"  name="valor6">menu1 </a>
  42. </div>
  43. </body>
  44. </html>
Advertisement
Add Comment
Please, Sign In to add comment