After loading reply in div without refresh, update div containing PHP/MYSQL search

Asked

Viewed 60 times

0

The page already loads the content in a div without refresh, the problem is the following:

It carries the answer inside a div rem refresh, giving the answer, I need that if the product is added, that it refresh tbm in the div that shows the products.

In the image the blue circular part is the response div and the red one is the one that needs to be updated showing the new product inserted.

inserir a descrição da imagem aqui

    <script>
$(document).ready(function() {
   //definir evento "onclick" do elemento (botao) ID butEnviar 
   $("#inserir-produto").click(function() {

      //capturar o valor dos campos do fomulario
      var DESCRICAO =  $("input[name=DESCRICAO]").val();
      var TAMANHO =  $("input[name=TAMANHO]").val();
      var COR = $("input[name=COR]").val();
      var QUANTIDADE = $("input[name=QUANTIDADE]").val();
      var VALORUNIT = $("input[name=VALORUNIT]").val();
      var NOME = $("input[name=NOME]").val();
      var OBSERVACAO = $("input[name=OBSERVACAO]").val();
      var botaonome = "inserir-produto";
      var numeropedido = "<? echo $IDPedido; ?>";

       // Exibe mensagem de carregamento
      $("#status").html("<center><img src='template/<? echo $SITE["TEMPLATE"]; ?>/img/load/InternetSlowdown_Day.gif' alt='Enviando' /></center>");
      //usar o metodo ajax da biblioteca jquery para postar os dados em processar.php
      $.ajax({
         "url": "funcoes/teste.php",
         "dataType": "html",
         "data": {
            "DESCRICAO" : DESCRICAO,
            "TAMANHO": TAMANHO,
            "COR" : COR,
            "QUANTIDADE" : QUANTIDADE,
            "VALORUNIT" : VALORUNIT,
            "NOME" : NOME,
            "OBSERVACAO" : OBSERVACAO,
            "botaonome" : botaonome,
            "numeropedido" : numeropedido
         },
         "success": function(response) {
            //em caso de sucesso, a div ID=saida recebe o response do post
            $("div#status").html(response);
         }

      });
   });
});
</script>

Div with the content of the products is another, how do I update it showing the new product added ?

    <div class="form-produtos" id="produtos-inseridos">



                                        <?php
    //--------------------------------------------------------------------------------------
    // Buscamos e exibimos as mensagens já contidas no banco de dados
    //--------------------------------------------------------------------------------------
    $query = mysql_query("SELECT * FROM painel_pedido_itens WHERE pedido='$IDPedido' ORDER BY id DESC");
    if(!mysql_affected_rows($query)){
        echo '
                                        <table border="1" width="100%">                                          
                                        <tr>
                                        <td align="center" width="5%">ID</td>
                                        <td align="center" width="25%">DESCRIÇÃO</td>
                                        <td align="center" width="6%">TAM</td>
                                        <td align="center" width="13%">COR</td>
                                        <td align="center" width="6%">QUANT</td>
                                        <td align="center" width="10%">VALOR UNIT</td>
                                        <td align="center" width="15%">NOME</td>
                                        <td align="center" width="15%">OBSERVAÇÃO</td>
                                        <td align="center" width="5%">OPÇÃO</td>
                                        </tr>
                                        ';

    while($mensagem = mysql_fetch_object($query)) {
        echo '
        <tr>
                                        <td align="center" width="5%">' . $mensagem->id . '</td>
                                        <td align="center" width="25%">' . $mensagem->descricao . '</td>
                                        <td align="center" width="6%">' . $mensagem->tamanho . '</td>
                                        <td align="center" width="13%">' . $mensagem->cor . '</td>
                                        <td align="center" width="6%">' . $mensagem->quantidade . '</td>
                                        <td align="center" width="10%">' . $mensagem->valorunit . '</td>
                                        <td align="center" width="15%">' . $mensagem->nome . '</td>
                                        <td align="center" width="15%">' . $mensagem->observacao . '</td>
                                        <td align="center" width="5%"><i class="icon-large icon-remove
"></i></td>
                                        </tr>
        ';      
    }
    echo '</table>';
    }
    else
    {
        echo "<center>Nenhum produto adicionado</center>";
    }
    ?>
 </div> <!-- /form-actions -->
  • 1

    I have the impression that there are several questions with this type of doubt here on the site. You have researched some way?

  • If you want a Ubmit without reflesh is with the ajax itself, I know no other way. Put your statement in the "Success" of ajax, then you can do whatever you want in any html element.

No answers

Browser other questions tagged

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