Send Ajax Variant to PHP

1

I'm having trouble sending an Ajax variable to PHP, the situation is as follows:

Using while , all available albums in the database are listed:

  include './bd/conecta.php';

  $sql = "SELECT * FROM album";
  $query = mysql_query($sql);

  while ($row = mysql_fetch_array($query)) {
      echo '<a href="">' . '<img  width="100px" heigth="100px" src="' . $row['capa_album'] . '"  onclick="alb(' . $row['id_album'] . ')" ></a>';
  }

Ajax code I can see this id_album through alert , but I can not send this id_album variable to the fotos.php page.

function alb(codigo) {
    $.ajax({
        url: 'fotos.php',
        cache: false,
        type: 'POST',
        data: 'id_album=' + codigo,
        success: function(data) {

            alert(codigo);
        }
    });
};

Actually neither redirecting is to the fotos.php page, can anyone help me?

    
asked by anonymous 21.10.2016 / 01:23

1 answer

0

The idea of ajax is to make requests without refresh, when the answer comes you use javascript to make changes to the page giving the impression that everything is happening in real time.

So when you click on one of the mounted links the data will be sent and processed for photos.php, there will be no redirection, it will be returned to the ajax what the photos.php render (write on the screen to be more precise).

table.php

 <table>
     <tr><td>CLIQUE EM MIM<td></tr>    
 </table>

 // bloco ajax
 $('tr').click(function(){
     $.ajax({type:'get';
         url:'numero.php',
         success: function(i){$('table tr').html('<td>'+i+'</td>')}
     })
 });

numero.php

echo 1

will produce:

 <table>
     <tr><td>1<td></tr>    
 </table>
    
21.10.2016 / 17:53