Pass GET method by Jquery

Asked

Viewed 704 times

0

I have the following situation, when I test is passing the parameter with var_dump, does not return.

What I’m trying to do is not load a new page but let it all happen on Divs.

HTML:

<td align="center"> 
    <?php echo '<a id="consulta" href="ver_imagem.phpid='.$aquivos['id_img'].'">Imagem '.$aquivos['id_img'].' </a>'; ?>
</td>

In the script try that:

<script type="text/javascript">
    jQuery(document).ready(function(){

        jQuery('#consulta').click(function(){
            var dados = jQuery( this ).serialize();

            jQuery.ajax({
                type: "GET",
                url: "ver_imagem.php",
                data: dados,
                success: function( data )
                {
                $("#imagens_pn").empty();
                $("#imagens_pn").append(data);

                }
            });

            return false;
        });
    });             
</script>
  • You can put the PHP part in the question too?

  • href="ver_imagem.phpid='. $aquivos['id_img']. '" wouldn’t be href="ver_imagem.php? id='. $aquivos['id_img'].'"

2 answers

0


From what I understand you want to pass the link href by jquery, if it is that follows below the problem is to serialize:

<?php echo '<a id="consulta" href="id='.$aquivos['id_img'].'">Imagem '.$aquivos['id_img'].' </a>'; ?>


<script type="text/javascript">
    $(document).ready(function(){

        jQuery('#consulta').click(function(){

          var me = $(this);
          var dados = me.attr("href");

            jQuery.ajax({
                type: "GET",
                url: "ver_imagem.php",
                data: dados,
                success: function( data )
                {
                $("#imagens_pn").empty();
                $("#imagens_pn").append(data);

                }
            });

            return false;
        });
    });             
</script>
  • Thanks Solange, that’s what you really need!!!!

0

 jQuery.ajax({
            type: "GET",
            url: "ver_imagem.php",
            data: {
                nomeVariavelServer: $("#consulta").attr("href")
            },
            success: function (data) {
                $("#imagens_pn").empty();
                $("#imagens_pn").append(data);

            }
        });

The variable name must be equal to the expected parameter in the api. API:

metodo(nomeVariavelServer)
{

}

Browser other questions tagged

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