Send Variable Ajax to PHP

Asked

Viewed 44 times

1

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

Through a while, are listed all albums available in the database:

  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>';
  }

Ai with the Ajax code I can visualize this id_album through a alert, but I can’t send this variable id_album to the page fotos.php.

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

            alert(codigo);
        }
    });
};

Actually not even redirecting is to the page photos.php, anyone can help me?

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.php photos, there will be no redirection, will be returned to the ajax what the.php photos process (write on the screen to be more accurate).

php table.

 <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>')}
     })
 });

php number.

echo 1

will produce:

 <table>
     <tr><td>1<td></tr>    
 </table>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.