Change data without refresh with jquery

3

I confess that I do not get much of Jquery and so I need help. I would like to update an information of a product, but without having to refresh the page. Example.:

When the user clicks the Main Photo link

Automaticallychangetheimagebelow:

TheproblemisonlyinJqueryandnotinthechangeintheDBthatI'mdoingwithPHP/Mysql.

Thelinkcodeisbelow:

$mostrar.="<a href='?principal=s&foto=".$jmFotos->IDFotos."&key=".$keyProdutos."' class='btn btn-primary btn-xs'>Foto Principal</a>";
    
asked by anonymous 04.11.2017 / 13:52

2 answers

2

I think I'm trying to send data to the database without the page refreshing, so if this is what I'm thinking in terms of what I read in the question. there goes a script so you do not have refresh

on your page simply change your form to form action="" method="" class="ajax"

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

            var dados = jQuery(this).serialize();


            $.ajax({
                    type: "POST",
                    url: "salvar.php", /* aqui voce insere o nome do arquivo */
                    data: dados,
                    success: function( data )
                    {
                            alert( data );
                    }
            });

            return false;
    });
});
</script>
    
04.11.2017 / 14:43
1
$('.envia_imagem').click(function(){
  $.ajax({
    url: 'url que recebe.php',
    method: 'POST',
    data: $('.input_com_a_imagem'),
    beforeSend: function(){
      alert('enviando'):
    },
    success: function(e){
      alert('funcionou');
    }
  });
});

I think it works, just edit the id's / classes

I have not tested it so far, and the jquery links

    
04.11.2017 / 14:02