将回应的HTML代码(PHP)附加到Javascript

We have a web application for billing, it gives print from browser. If we give print from browser to dotmatrix printer there will be a speed issue(it pirnts very very slow). So we plan to send raw texts to printer without intervention of browsers print view.

For that i came to know jZebra plugin. It invokes print through java using javascript. By the jzebra tutorial i can append some html and i cant print some text, working fine. like below

<script>
        function print() {
        qz.appendHTML('<html><table style="font-size:10pt; font-face:\'Courier New\';"><tr>' + 
                        '<td colspan="3">Company Name</td>' + 
                        '</tr><tr>' +
                        '<td>TIN: number</td>' + 
                        '<td>ADDRESS<br/>SILK SHOWROOM A/C, PADIYUR</td>' + 
                        '<td>STD: 0000000000/td>' + 
                        '</tr></table></html>');
         // Send characters/raw commands to printer
         qz.printHTML();
    }
</script>

The Problem:

While billing im echoing some HTML like products purchase details and total amounts through PHP on a button click event.

How can i append those HTMLs to the above function?

some of code samples here Calling this PHP through ajax : retail_sales_nontextile_add.php

  try{
        //SELECTING DATA FRO VIEW FROM VI TEMP
        $stmt = $pdo->prepare("SELECT * FROM nontextile_purchase_retailsales_wholesales WHERE bill_number = '$bill_no' ORDER BY id ASC"); $stmt->execute();
        $results            =   $stmt->fetchAll();
     }
     catch(Exception $e){
             print_r($e->getMessage());
             exit;
         }

    foreach($results as $result){
            echo "<tr style='margin-top:-37px;' class='active'><td class='center'></td>";
            echo "<td class='left'>".$result['variety']."</td>";
            echo "<td class='right'>".$result['price']."</td>";
            echo "<td class='center'>".$result['quantity']."</td>";
            echo "<td class='right total'> ".$result['total']."</td>";
            echo "<!--<td class='hidden-print center'><a id='retailsale_nontextile_edit' category ='".$result['category']."' variety='".$result['variety']."' price='".$result['price']."' commision_percent='".$result['commision_percent']."' bill_no='".$result['bill_number']."'>Edit</a></td>-->";
            echo "<td class='hidden-print center'><a id='retailsale_nontextile_delete' id_to_delete='".$result['id']."' bill_no='".$result['bill_number']."'>Delete</a></td></tr>";
                }
                echo "</tbody>
                </table>

with the above echoed HTML how can i append it in the javascript function? AJAX is HERE:

$.post(
             "./php/retailsale/retail_sales_nontextile_add.php",
             { bill_no: bill_no, sale_date: sale_date, category: category, variety: variety, price: price, quantity: quantity, total: total },
             function(data) {
                $('#print_area').html(data);
             }).done(function( data ) {

          });

Thanks for ur help....

I can think of a few methods you could pass the data to the print. If the two functions are always run together then you can call the post from inside the print or pass the data directly to print:

function print() {
        $.post(
             ...
             }).done(function( data ) {
                 qz.appendHTML('...' + data + '...');
          });
}

or the opposite method:

$.post( 
...
                 }).done(function( data ) {
                     print(data)
              });

then use the data in the print function

function print(data) {
...
}

lastly, if the two functions are independent, you could create a global variable like append outside of the functions.

var append;
$.post( 
...
                 }).done(function( data ) {
                     append = data;
              });
function print() {
   ... + append + ...
}