Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

93
Visualizações
While loop wont print twice

Currently I'm trying to print two copies of the same receipt without using the browser-print dialogue. Now unfortunately there is no way to pass the number of copies to the print dialog so the only solution I came up with is doing it in a LOOP, but when looping the print command it does not work! while looping the whole POST method works just fine.

Here's the code before I enter the loop
print function

function p_print(receipt) {

        $('#receipt_section').html(receipt.html_content);
        __currency_convert_recursively($('#receipt_section'));
        __print_receipt('receipt_section');
    
}

Code without Loop

        $.ajax({
            method: 'POST',
            url: url,
            data: data,
            dataType: 'json',
            success: function(result) {
                if (result.success == 1) {
                    if (result.mail_enabled) {
                        window.open(result.mail_enabled);
                    }
                    $('#modal_payment').modal('hide');
                    toastr.success(result.msg);


                    //Check if enabled or not
                    if (result.receipt.is_enabled) {
                        p_print(result.receipt);
                    }
                } else {
                    toastr.error(result.msg);
                }
            },
        });

Functioning loop that prints twice but also POSTS the data twice

        var Count = 0;
        var Copies = 2; 
        while ( Count < Copies ) {
        $.ajax({
            method: 'POST',
            url: url,
            data: data,
            dataType: 'json',
            success: function(result) {
                if (result.success == 1) {
                    if (result.mail_enabled) {
                        window.open(result.mail_enabled);
                    }
                    $('#modal_pay').modal('hide');
                    toastr.success(result.msg);


                    if (result.receipt.is_enabled) {
                        p_print(result.receipt);
                    }
                } else {
                    toastr.error(result.msg);
                }
            },
        });
        Count ++;  
        };

Now If I apply the loop only on p_print(result.receipt) it wont print twice, only by applying it to the whole POST request it would then print twice but also stores the data twice which is not a proper solution at all.

Any help would be very appreciated.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda