Updating data from a div?

0

How do I update the information of a div element with jQuery without necessarily reloading the page?

Ex: Send a post of a insert and the information of that insert will soon appear in div pulling from the bank.

    
asked by anonymous 09.06.2014 / 19:10

2 answers

3

Use the $.post function of JQuery:

$("#form").submit(function() { // QUANDO ENVIAR O FORM
    var login = $("#login").val(); // VALOR DO LOGIN
    var senha = $("#senha").val(); // VALOR DO INPUT SENHA
        $.post('logar.php', { // FUNÇÃO POST, LOGAR.PHP FAZ A INSERÇÃO NO MYSQL             
            login: login,
            senha: senha
        }, function(resposta) {
            $("#divresposta").html(resposta); // RESPOSTA
        }, 'html');
        return false;
});
    
09.06.2014 / 19:42
2

Study the $.ajax function:

$.ajax({
  type: "POST",
  url: url,
  data: data,
  success: success,
  dataType: dataType
});

Source: link

You can do the following (I did not test, but it's basically this):

$.ajax( {
    url: "insert_func.php",
    type: "post",
    data: { name: "bruce", age: 23 }, // dados que serão processados
    success: function(response) {
        $(".your-div-class").html(response);
    }
});
    
09.06.2014 / 19:17