简体   繁体   English

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

[英]Appending Echoed HTML code (PHP) to Javascript

We have a web application for billing, it gives print from browser. 我们有一个用于计费的Web应用程序,它可以通过浏览器进行打印。 If we give print from browser to dotmatrix printer there will be a speed issue(it pirnts very very slow). 如果我们将浏览器的打印内容提供给dotmatrix打印机,则会出现速度问题(打印速度非常慢)。 So we plan to send raw texts to printer without intervention of browsers print view. 因此,我们计划将原始文本发送到打印机,而无需浏览器干预打印视图。

For that i came to know jZebra plugin. 为此,我认识了jZebra插件。 It invokes print through java using javascript. 它使用javascript通过java调用print。 By the jzebra tutorial i can append some html and i cant print some text, working fine. 通过jzebra教程,我可以附加一些html,但是我不能打印一些文本,可以正常工作。 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. 帐单即时通讯会在按钮点击事件中通过PHP回显某些HTML,例如产品购买明细和总金额。

How can i append those HTMLs to the above function? 如何将这些HTML附加到上述函数中?

some of code samples here Calling this PHP through ajax : retail_sales_nontextile_add.php 这里的一些代码示例通过ajax调用此PHP: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? 与上述回显的HTML我如何将其附加在javascript函数中? AJAX is HERE: AJAX在这里:

$.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. 最后,如果两个函数是独立的,则可以在函数外部创建一个像append这样的全局变量。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM