How to print html content from a div when I save the information in the database?

0

Good evening,

I have a system of control of inputs and outputs of computer repairs what I intend and that when I save the information in the database soon after I gave myself to print the html content of a div where the stored data will be recorded.

In this case, I want it to be saved successfully and open the option to print the contents of the div.

<script> 
$(document).on("click", "#novo", function(e) { 
    tinyMCE.triggerSave();
    var postData = $("#form_novo").serialize();
    var cliente = $("#cliente").val();
    var avaria = $("#avaria").val();
    if(cliente === '' || avaria === ''){
        toastr.error('Preencha os campos obrigatórios!', 'Campos');
    }else{
        e.preventDefault();
        $.ajax({
            type: "POST",
            url: "modulos/reparacoes/guardar.php",
            data: postData,
            cache: true
        }).done(function(msg) {
            toastr.success('Dados guardados com sucesso!', 'Reparações');
        }).fail(function(data) {
            toastr.error('Ocorreu um erro!', 'Erro');
        });
    }
});    
</script>
    
asked by anonymous 06.04.2016 / 00:40

1 answer

0

If the recording is successful, you should return all the data you want in JSON from the server.

EXAMPLE:
{NAME: 'test', CONTACT: '123'}

In php to return this JSON
print_r (json_encode (array ('NAME' => 'test', 'TELEPHONE' => '123')));

In the function that already has in AJAX the done should make visible the option to print. (You can put it visible if it already exists or you can create the button / image) And should make a code similar to:

  msg=JSON.parse(msg); //a variável msg é a variável que recebe no done
  //Vamos supor que essa opção tem o ID igual a ImprimirDados.
  $('#ImprimirDados').on('click',function(){ 
     for (var dados in msg){
        //dados tem o índex JSON exemplo NOME
        //msg[dados] tem o valor JSON exemplo teste
        //Se os índex tiverem os mesmo nomes dos campos
        $('#'+dados).val(msg[dados]);
     }
 });
    
06.04.2016 / 19:01