Refresh DIV without refresh with Ajax

1

I have an ajax that sends through post , some information in PHP to another page. I save this information in session .

I would like to update the div where I have a modal. In case, this modal would have to refresh without giving refresh in the entire page, only in it to get the value of $_SESSION['IMPR_PEDIDO']['pedido'] current. Does anyone know how to do it?

<div class="modal fade" id="altera_cliente" tabindex="-1" role="dialog" aria-labelledby="modalLabel">
   <div class="modal-dialog" role="document">
      <div class="modal-content">
         <div class="modal-header modal_pedido">
            <button type="button" class="close" data-dismiss="modal" aria-label="Fechar"><span aria-hidden="true">&times;</span></button>
            <h4 class="modal-title" id="modalLabel">PedidoOnline gerado com sucesso!</h4>
         </div>
         <div class="modal-body">
            <div class="row">
               <div class="form-group">
                  <a class='btn-info btn-mini' href='pedidos_pdf/pedido_/<?php echo $_SESSION['IMPR_PEDIDO']['pedido']; ?>.pdf' target='_blank' download='Pedido_<?php echo $_SESSION['IMPR_PEDIDO']['pedido']; ?>'><img border='0' src='./images/download9.png' alt='W3Schools'></a>
               </div>
               <p />
            </div>
         </div>
         <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">Sair</button>
         </div>
      </div>
   </div>
</div>

javascript code:

$(document).ready(function () {
   $('.informacoes').click(function () {
      var dados = $(this).val();
      $.ajax({
         type: 'GET',
         url: './ajax/pdf_pedido_faturado.php',
         data: 'pedido=' + dados,
         beforeSend: function () {
            $('<div class="ajaxModal"><div class="ajaxModal-preload"><p>Salvando PDF aguarde!</p></div></div>').insertAfter('body');
            $('.ajaxModal').fadeIn('fast');
         },
         success: function () {
            ajaxModal_Close();
            $('#altera_cliente').modal('show');
         }
      });
      return false;
   });
});
    
asked by anonymous 08.07.2016 / 21:09

1 answer

0

PHP is generated only once on the server side and then transferred with all necessary information to the browser and renders the page.

What you can do is build a .php file that echoes this session variable and using jquery you call and populate your div.

<?php
    echo $_SESSION['IMPR_PEDIDO']['pedido'];
?>

In jquery you can do so

/* evento que abre é disparado quando o modal 
do bootstrap é aberto (supondo que voce está usando bootstrap*/

$('#meuModal').on('show.bs.modal', function () {
    var callString = "url.php";
    $.get(callString, function (result) {
        $("#minhaDiv").text(result);
    });
});
    
15.07.2016 / 20:14