Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2014
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.10 KB | None | 0 0
  1. /*
  2.  * Exemplo de acordo com o que pediste.
  3.  * 1) - Ficheiro index.php = ficheiro que contém a tabela
  4.  * 2) - Ficheiro ajax.php  = ficheiro que vai receber os dados da tabela do index.php
  5. */
  6.  
  7. index.php
  8.  
  9. <html>
  10.   <head></head>
  11.   <body>
  12.  
  13.    <table id="tabela_XPTO">
  14.      <tr>
  15.        <td>Novos</td>
  16.        <td>Horizontes</td>
  17.      </tr>
  18.    </table>
  19.    <button id="button_XPTO">Clica-me fax fabor!</button>
  20.  
  21.    <script>
  22.       $(document).on('click', '#button_XPTO', function(){
  23.        
  24.         var values = [];
  25.      
  26.         $("#tabela_XPTO").find('tr').each(function(){
  27.  
  28.             var $td = $(this).find('td');
  29.             values.push({'id': $td.eq(0).text(), 'nome': $td.eq(1).text()});
  30.  
  31.             /* $td.eq(0).text = "novos" :: $td.eq(1).text = "horizontes" */
  32.         });
  33.  
  34.         $.post('responses/ajax.php', {valores: values}, function(aux){
  35.            console.log(aux);
  36.         });
  37.       });
  38.    </script>
  39.   </body>
  40. </html>
  41.  
  42.  
  43. ajax.php
  44.  
  45. print_r($_POST);
  46. // E em princípio receberás na consola do Chrome os valores.
  47. // Depois é só pegares neles e inserires na base de dados.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement