Update DIV without refresh with Ajax

Asked

Viewed 1,389 times

1

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

I would like to update the div where I have a modal. In this case, this modal would have to update without refreshing the whole page, only in it to get the value of $_SESSION['IMPR_PEDIDO']['pedido'] current. Someone knows how to do?

<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;
   });
});
  • What pdf_pedido_invoiced.php returns (HTML, Json, string)?

  • In this file I select and save a PDF file in a folder of my site, then record a $SESSION['numero'] , i’m not returning anything just this Septssion.

  • Want to update the div with what content?

  • I want to update the div with the value that is in $_SESSION

  • <a class='btn-info btn-mini' href='pedidos_pdf/pedido_/<? php echo $_SESSION['IMPR_PEDIDO']['request']; ? >. pdf' target='Blank' download='Request<?php echo $_SESSION['IMPR_PEDIDO']['request']; ? >'><img border='0' src='. /images/download9.png' alt='W3schools'></a>

1 answer

0

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

What Voce can do is build a file . php which gives an echo of this session variable and using jquery Voce calls and populates your div.

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

In jquery Voce 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);
    });
});
  • Face sorry my ignorance but do not understand, I’m doing the following cool. I have the file busca_fotos.php in it I have a require 'busca_fotos_mostra.php'; when I click on the photo boot of my list it fires an ajax that sends the data via POST to another PHP file that searches the name of the photo file and saved in Sesssion, below my ajax.

  • I don’t think your comment fits in one piece, Maicon...

  • This is the part that opens the modal only error in the modal, remembering that the modal is another file. Success: Function (date) { if (date === 'FOTOS_OK') { ajaxModal_Close(); $('#photos'). load('consulta_prodo_fotos.php'); $('#fotos_prod'). modal('show'); } Else if (date === 'NAO_FOTOS') { //Alert(product); ajaxModal_Close(); $("#fotos_nao"). modal(); } }

  • What you need is to show the name of the photo that is in the session in the modal title '#fotos_prod', this?

  • In fact in my modal I have a Carrousel la faco foreach to display on the screen the information that was saved in the Session so that of the error foreach ($_SESSION['photos'] as $key => $value): display the information Notice: Undefined index: Photos in C: wamp www incoterm consulta_produto_fotos.php on line 33

  • You are saving an array within this variable?

  • Could you give a Skype help later put the solution here.

Show 3 more comments

Browser other questions tagged

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